没意思先生 2015-07-19 13:09 采纳率: 40%
浏览 1490
已结题

为什么最小化后Panel就超出主界面范围

Panel

 public class GameJPanel extends JPanel {
    private static final long serialVersionUID = 1L;
    private Image image;
    Random rand = new Random();
    public ArrayList<Fish> fishes=new ArrayList<Fish>();


    public GameJPanel() {
        this.setBounds(40, 65, 800, 480);
        image = Toolkit.getDefaultToolkit().getImage("image/mainbg.png"); 

        this.setVisible(true);


    }

    public void paintComponent(Graphics g)
    {
        g.drawImage(image,0,0, this.getWidth(), this.getHeight(),this);

    }



    }

MainFrame

public class MainJFrame extends JFrame implements ActionListener ,Observer{
    private static final long serialVersionUID = 1L;
    private StartJPanel panel; //开始界面
    private GameJPanel mainpanel; //游戏界面
    private HelpJPanel helppanel;
    JLabel mainLabel;
    JButton min, close;
    int x;
    int y;
    protected boolean  isStart;
    protected boolean  isExit;
    protected boolean  isHelp;

    public MainJFrame(Observable ob)
    {
        ob.addObserver(this);
        Observable obs = ob;

        this.panel = new StartJPanel(obs);
        this.mainpanel = new GameJPanel();
        this.helppanel=new HelpJPanel();
        // 设置窗体可以跟随鼠标移动和透明
        new GameUtil(this);
        this.isStart = panel.getIsStart();
        this.isExit  = panel.isExit();
        this.isHelp=panel.getIsHelp();
    }

    public void showMyFrame(){
        this.add(this.panel);
        x=Toolkit.getDefaultToolkit().getScreenSize().width;
        y=Toolkit.getDefaultToolkit().getScreenSize().height;
        this.setBounds((x-880)/2,(y-580)/2,880,580);
        this.setUndecorated(true);
        this.setIconImage(new ImageIcon("image/icon.png").getImage());
        mainLabel=new JLabel(new ImageIcon("image/bg.png"));
        min = new JButton(new ImageIcon("image/min.png"));
        close = new JButton(new ImageIcon("image/close.png"));
        close.setBounds(810, 28, 32, 32);
        close.setBorderPainted(false);
        close.setContentAreaFilled(false);
        mainLabel.add(close);
        min.setBounds(772, 28, 32, 32);
        min.setBorderPainted(false);
        min.setContentAreaFilled(false);
        mainLabel.add(min);
        min.addActionListener(this);
        close.addActionListener(this);
        this.add(mainLabel);
        this.setVisible(true);

    }


    public void update(Observable arg0, Object arg1) 
    {
        StartJPanel panel = (StartJPanel) arg1;
        //System.out.println("update" + panel.getIsStart());
        if(panel.getIsStart())
        {

            //移除mainPanel对象
            this.remove(this.panel);
            //添加Panel对象
            this.add(this.mainpanel);
            this.repaint();
        }
        if(panel.getIsHelp())
        {

            //移除mainPanel对象
            this.remove(this.panel);
            //添加helpPanel对象
            this.add(this.helppanel,BorderLayout.CENTER);
            this.repaint();
        }
    }

    public void changedPanel()
    {

    }


    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == min) {
            this.setState(JFrame.ICONIFIED);
        } else if (e.getSource() == close) {
            System.exit(0);
        }
    }
    public void setDefaultCloseOperation(boolean b) {

    }
} 
  • 写回答

3条回答

  • 飞侠老蒋 2015-07-19 13:32
    关注

    我感觉是设定宽度和图片不一致,导致撑了!!!

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。