0
上午試圖調用行動油漆執行,但它不能正常工作的Java如何調用paint在actionperform
btnNewButton_5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
class MyCanvas extends JComponent {
public void paint(Graphics g) {
g.drawLine(10,20,50,60);
}
}
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(30, 30, 300, 300);
window.getContentPane().add(new MyCanvas());
window.setVisible(true);
}
});
問題是,它僅顯示框,但矩形不畫
我怎麼可以編輯這個代碼幫助我
http://stackoverflow.com/questions/21421150/java-using-graphics-component-within-an-actionlistener – pinkpanther