图形将在标题栏中保留渲染。我使用封装在jlabel中的缓冲Image,并使用生成的图形对象在代码中绘制矩形。这是jframe类构造函数的重要部分:
super();
BufferedImage image=new BufferedImage(680,581,BufferedImage.TYPE_INT_ARGB);
m_graphicsObject =image.getGraphics();
JLabel label=new JLabel(new ImageIcon(image));
// buttons, mouse events and other controls use listeners to handle actions
// these listener are classes
btn1 = new JButton("Go!");
//btn1.setPreferredSize(new Dimension(100, 30));
btn1.addActionListener(new button_go_Click()); //listener 1
btn2 = new JButton("Clear!");
//btn2.setPreferredSize(new Dimension(100, 30));
btn2.addActionListener(new button_clear_Click()); //listener 2
//always add created buttons/controls to form
JPanel panel=new JPanel(new GridLayout(20,2));
panel.add(btn1);
panel.add(btn2);
Container pane = this.getContentPane();
pane.add(label);
pane.add(panel, BorderLayout.EAST);
this.setSize(680,581);
this.setVisible(true);
婷婷同学_
相关分类