我试图从方法paint(Graphics g)
中的JTextFields获取4个整数参数我正在解析用户输入为整数然后我试图将其解析为方法`g.drawRect(x1,y1,x2) ,y2); ,但是当我运行应用程序时,我根本没有任何矩形。这是代码:
点击按钮:
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Figure();
}
});
public void paint(Graphics g) {
int x1 = Integer.parseInt(textField.getText().toString());
int y1 = Integer.parseInt(textField_1.getText().toString());
int x2 = Integer.parseInt(textField_2.getText().toString());
int y2 = Integer.parseInt(textField_3.getText().toString());
g.drawRect (x1, y1, x2, y2);
}
private void Figure()
{
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(30, 30, 300, 300);
window.getContentPane().add(new Form());
window.setVisible(true);
}
谢谢你的建议!