0

GUI と Customer クラスの 2 つのクラスがあります。GUI がフレームとボタンを作成し、Customer クラスがデータベース サーバーから情報を取得します。Customer クラスに ActionPerformed がありますが、ボタンをクリックしても気付かないようです。どんな助けでも大歓迎です!

GUI クラス:

class GUI { 

private static JFrame frame;
public static JTextField textField;
public static JButton btnGetInfo = new JButton("Get Info");
public static JTextArea textArea = new JTextArea();

  public static void main (String args []) 
  throws SQLException { 

DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());


GUI window = new GUI();


frame = new JFrame();
frame.setBounds(100, 100, 630, 470);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);


textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setBounds(10, 179, 594, 241);
frame.getContentPane().add(textArea);


textField = new JTextField();
textField.setBounds(255, 69, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);


JButton btnClearScreen = new JButton("Clear Screen");
btnClearScreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

        textArea.setText("");

    }
});


btnClearScreen.setBounds(492, 11, 112, 23);
frame.getContentPane().add(btnClearScreen);


JLabel lblEnterCustomerId = new JLabel("Enter Customer ID (1-6)");
lblEnterCustomerId.setBounds(240, 43, 153, 14);
frame.getContentPane().add(lblEnterCustomerId);


btnGetInfo.setBounds(255, 115, 89, 23);
frame.getContentPane().add(btnGetInfo);


window.frame.setVisible(true);

} 
} 

顧客クラス:

public class Customer implements ActionListener {

public static void getInfoButton() {

GUI.btnGetInfo.addActionListener(new ActionListener() {


    public void actionPerformed(ActionEvent arg0) {

        System.out.println("TEST");

        String getCustID = GUI.textField.getText();
        String query = ("select * from customers where CUSTID =" + getCustID);

        final String user, pass;

        user = "asdf";
        pass = "asdf";


        try{

            Connection conn = DriverManager.getConnection
                    ("jdbc:oracle:thin:@asdf",user,pass);
                    Statement stmt = conn.createStatement (); 

            ResultSet rset = stmt.executeQuery (query);

            while (rset.next ()) 
                { 

                    GUI.textArea.append((rset.getString("CUSTID") + "  -  " + rset.getString("CUSTSSN")
                    + "  -  " + rset.getString("LNAME") + "  -  " + rset.getString("FNAME") + "  -  " +
                    rset.getString("STREET") + "  -  " + rset.getString("CITY") + "  -  " + rset.getString("STATE") +
                    "  -  " + rset.getString("ZIP") + "  -  " + rset.getString("PHONE") + System.getProperty("line.separator")
                    + System.getProperty("line.separator")));

                }    


        }

            catch (SQLException e)
        {
            System.out.println ("Could not load the db"+e); 
        }

    }});


}

@Override
public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub

}

}
4

1 に答える 1