JFrame 폼에서 텍스트 필드를 두 번 설정했지만 마지막으로 설정 한 텍스트 필드가 남아 있습니다. JFrame Form 외에도 더 많은 시간을 성공적으로 설정할 수 있습니다. 예 :JFrame 폼에서 여러 번 구성 요소를 설정하는 방법
class test extends JFrame {
public static void main(String[] args) {
test t = new test();
textfield.setText("Hello");
long a = System.currentTimeMillis();
long c = a;
while (c > a - 1000) {
a = System.currentTimeMillis();
}
textfield.setText("Hello2");
}
static private JTextField textfield;
public test() {
super();
setSize(300, 300);
textfield = new JTextField("Hello1");
add(textfield);
setVisible(true);
}}
위의 코드는 성공적으로 실행 중입니다. 1 초 후에 "Hello"와 "Hello2"를 먼저 표시하십시오. 그러나 JFrame Form에는 "Hello"대신 "Hello2"만 표시됩니다.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("Hello");
long a = System.currentTimeMillis();
long c = a;
while (c > a - 1000) {
a = System.currentTimeMillis();
}
jTextField1.setText("Hello2");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(deneme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new deneme().setVisible(true);
}
});
}
또한 I는
repaint()
,
validate()
revalidate()
및 검색 방법. 하지만 내 프로젝트 JFrame 양식 때문에 JFrame 개체가 없습니다. 따라서 이러한 방법을 사용할 수 없습니다.
미리 답변 해 주셔서 감사합니다.
"실행되지 않음"이란 무엇을 의미합니까? 현재의 행동과 기대하는 행동을 설명하십시오. –
프로그램에서 수행하고자하는 작업을보다 정확하게 할 수 있습니까? – whyn0t
@KrzysztofKosmatka 텍스트 필드에는 "Hello2"만 표시됩니다. 나는 "Hello"다음에 "Hello2"라는 표시가 1 초 후에 나타날 것을 기대한다. 감사합니다 –