Java p> 谢谢。我只是想让这个延迟有点乐趣,否则它的工作会很好。此外,我无法理解事件调度线程(EDT)这个术语,因为我是GUI的初学者。有谁能提供正确的代码以正确的方式执行它。我已经给了你两种可能性。这就是教程链接的目的。它们提供了以正确方式进行操作的代码。阅
Java p> 谢谢。我只是想让这个延迟有点乐趣,否则它的工作会很好。此外,我无法理解事件调度线程(EDT)这个术语,因为我是GUI的初学者。有谁能提供正确的代码以正确的方式执行它。我已经给了你两种可能性。这就是教程链接的目的。它们提供了以正确方式进行操作的代码。阅,java,swing,timer,delay,jcombobox,Java,Swing,Timer,Delay,Jcombobox,p> 谢谢。我只是想让这个延迟有点乐趣,否则它的工作会很好。此外,我无法理解事件调度线程(EDT)这个术语,因为我是GUI的初学者。有谁能提供正确的代码以正确的方式执行它。我已经给了你两种可能性。这就是教程链接的目的。它们提供了以正确方式进行操作的代码。阅读教程。下载示例并使用它们。我们不是来为您编写代码的。如果这让您感到不安,很抱歉。我只是想在我错的地方得到一点帮助,非常感谢你的帮助和时间。谢谢。我只是想让这个延迟有点乐趣,否则它的工作会很好。此外,我无法理解事件调度线程(EDT)这个术语,因
p> 谢谢。我只是想让这个延迟有点乐趣,否则它的工作会很好。此外,我无法理解事件调度线程(EDT)这个术语,因为我是GUI的初学者。有谁能提供正确的代码以正确的方式执行它。我已经给了你两种可能性。这就是教程链接的目的。它们提供了以正确方式进行操作的代码。阅读教程。下载示例并使用它们。我们不是来为您编写代码的。如果这让您感到不安,很抱歉。我只是想在我错的地方得到一点帮助,非常感谢你的帮助和时间。谢谢。我只是想让这个延迟有点乐趣,否则它的工作会很好。此外,我无法理解事件调度线程(EDT)这个术语,因为我是GUI的初学者。有谁能提供正确的代码以正确的方式执行它。我已经给了你两种可能性。这就是教程链接的目的。它们提供了以正确方式进行操作的代码。阅读教程。下载示例并使用它们。我们不是来为您编写代码的。如果这让您感到不安,很抱歉。我只是想在我错的地方得到一点帮助,非常感谢你的帮助和时间。
package com.softoak.dba;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import javax.swing.JComboBox;
public class Login{
private JFrame frame;
static ArrayList<String> dbcom = new ArrayList<String>();
static String[] usecom;
JLabel status = new JLabel("•");
JLabel lblNotConnected;
/**
* Launch the application.
*/
public static void main(String[] args) throws Exception{
Connection m_Connection = DriverManager.getConnection("jdbc:sqlserver://localhost;integratedSecurity=true");
String dbs = "SELECT * FROM sys.databases WHERE owner_sid != 1";
Statement st = m_Connection.createStatement();
ResultSet m_ResultSet = st.executeQuery(dbs);
dbcom.add("-None-");
while(m_ResultSet.next()){
dbcom.add(m_ResultSet.getString(1));
}
usecom = new String[dbcom.size()];
usecom = dbcom.toArray(usecom);
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login window = new Login();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Login() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
status.setBounds(385, 235, 10, 10);
status.setForeground(Color.red);
frame.getContentPane().add(status);
JLabel lblLoginApplication = new JLabel("Login Application");
lblLoginApplication.setFont(new Font("Lucida Calligraphy", Font.BOLD, 20));
lblLoginApplication.setBounds(120, 25, 220, 30);
frame.getContentPane().add(lblLoginApplication);
JComboBox comboBox = new JComboBox(usecom);
comboBox.setBounds(230, 80, 110, 30);
comboBox.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if (comboBox.getSelectedIndex() == 1 || comboBox.getSelectedIndex() == 2) {
lblNotConnected.setText("Connecting...");
try{
Thread.sleep(5000);
}catch(InterruptedException ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
}
status.setForeground(Color.green);
lblNotConnected.setText("Connected");
JOptionPane.showMessageDialog(null, "Connected");
}
else{
status.setForeground(Color.red);
lblNotConnected.setText("Not Connected");
}
}
});
frame.getContentPane().add(comboBox);
JLabel lblSelectDatabase = new JLabel("Select Database");
lblSelectDatabase.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 14));
lblSelectDatabase.setBounds(91, 79, 129, 30);
frame.getContentPane().add(lblSelectDatabase);
lblNotConnected = new JLabel("Not Connected");
lblNotConnected.setFont(new Font("Elephant", Font.PLAIN, 12));
lblNotConnected.setBounds(280, 230, 110, 20);
frame.getContentPane().add(lblNotConnected);
}