如何解决为什么jframe在终止后会停止整个执行
实际上,我在这里在调用jframe类时遇到问题。在主要方法完成执行之前执行Jframe整理执行。
public class Connection2{
// public static final String HOST = "localhost";
// public static final String PORT = "5555";
public static String HOST;
public static String PORT;
public static long START;
public static long END;
public static void main(String[] args) throws InterruptedException,ClassNotFoundException,sqlException,IOException {
Frame1 frame = new Frame1();
Scanner sc = new Scanner(system.in);
System.out.println("JMX CONNECTION:");
System.out.println("HOST AND PORT");
frame.main(args); >here the GUI starts and after clicling Jbutton it stops
Thread.sleep(10000);
HOST = frame.textField.getText();
PORT= frame.textField_1.getText();
System.out.println(HOST);
System.out.println("TEST DURATION IN SECONDS");
System.out.println("DURATON(sec): ");
int Duration = sc.nextInt();
START = System.currentTimeMillis();
END = START + Duration*1000; // 60 seconds * 1000 ms/sec 60*1000= 1 minute
Connection2 object = new Connection2();
Csvwriter csv = new Csvwriter();
MenuDrivenSystem menu = new MenuDrivenSystem();
Thread.sleep(3000);
while(System.currentTimeMillis() < END){
try
{
object.waitMethod();
Thread.sleep(2000);
}
catch(Exception E)
{
E.printstacktrace();
//JOptionPane.showMessageDialog(null,"CSV NOT SAVED");
}
}
csv.main(args);
System.out.println("Database and csv push done............");
menu.main(args);
}
'''
这是我的jFrame类 '''
public class Frame1 {
public JFrame frame;
public JTextField textField;
public JTextField textField_1;
public JTextField textField_2;
public JLabel lblNewLabel;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokelater(new Runnable() {
public void run() {
try {
Frame1 window = new Frame1();
window.frame.setVisible(true);
} catch (Exception e) {
e.printstacktrace();
}
}
});
}
/**
* Create the application.
*/
public Frame1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
public void initialize() {
frame = new JFrame();
frame.getContentPane().setBackground( new Color(240,240,240));
frame.setBounds(100,100,450,300);
frame.setDefaultCloSEOperation(JFrame.disPOSE_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton btnNewButton = new JButton("Connect");
btnNewButton.setForeground(Color.BLACK);
btnNewButton.setBackground(Color.GRAY);
btnNewButton.setFont(new Font("Tahoma",Font.BOLD,16));
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//messape
String userText;
String pwdText;
userText = textField.getText();
pwdText = textField_1.getText();
System.out.println(userText);
if(e.getSource()==btnNewButton) {
System.exit(0);
// This exit Your GUI
}
}
});
btnNewButton.setBounds(156,142,115,29);
frame.getContentPane().add(btnNewButton);
textField = new JTextField();
textField.setBounds(144,16,146,26);
frame.getContentPane().add(textField);
textField.setColumns(10);
lblNewLabel = new JLabel("URL OR HOST:");
lblNewLabel.setBounds(28,18,114,23);
frame.getContentPane().add(lblNewLabel);
textField_1 = new JTextField();
textField_1.setBounds(144,58,26);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setBounds(144,26);
frame.getContentPane().add(textField_2);
textField_2.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("PORT:");
lblNewLabel_1.setBounds(38,61,75,20);
frame.getContentPane().add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("DURATION(S):");
lblNewLabel_2.setBounds(27,103,20);
frame.getContentPane().add(lblNewLabel_2);
}
}
''' 我希望在打开GUI后,它应该接受用户的输入,然后关闭窗口并移至下一行代码
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。