图形继续在标题栏中呈现。我使用封装在 jlabel 中的缓冲图像,并使用生成的图形对象在我的代码中绘制矩形。这是 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);