1
我會運行程序,但是當我激活事件時,JFrame不會更新(它只會刪除JLabel),除非手動拖動窗口來調整它的大小,即使在事件發生後調用repaint() 。怎麼了?試圖更新我的JFrame,爲什麼不重繪工作?
public Driver() {
setLayout(new FlowLayout());
pass = new JPasswordField(4);
add(pass);
image = new ImageIcon("closedD.png");
label = new JLabel("Enter the password to enter the journal of dreams" , image , JLabel.LEFT);
add(label);
button = new JButton("Enter");
add(button);
event e = new event();
button.addActionListener(e);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setSize(1600/2 , 900/2);
setTitle("Diary");
}
//main method
//
//
public static void main(String[] args) {
win = new Driver();
}
public class event implements ActionListener {
private boolean clickAgain = false;
public void actionPerformed(ActionEvent e) {
if (passEquals(password) && clickAgain == false) {
image2 = new ImageIcon("openD.png");
remove(label);
label = new JLabel("Good Job! Here is the journal of dreams." , image2 , JLabel.LEFT);
add(label);
clickAgain = true;
}
repaint();
}
}
非常感謝! –
@MarkdelaCruz:不客氣! –
我的不好。我錯過了你的編輯。同意CL會在這裏矯枉過正。 +1 –