Witam.
Przygotowuję prosty program do łączenia z bazą danych. Aktualnie posiadam dwie klasy:
- Interface
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
public class Interface extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Interface frame = new Interface();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Interface() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 615, 300);
setTitle("DefectLoader");
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Login");
lblNewLabel.setBounds(10, 8, 65, 14);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Password");
lblNewLabel_1.setBounds(10, 40, 65, 14);
contentPane.add(lblNewLabel_1);
textField = new JTextField();
textField.setBounds(80, 5, 100, 20);
contentPane.add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(80, 35, 100, 20);
contentPane.add(textField_1);
textField_1.setColumns(10);
JButton btnNewButton = new JButton("Connect");
btnNewButton.setBounds(10, 85, 170, 23);
contentPane.add(btnNewButton);
}
}
- Connect
public class Connect {
public static void method_connect() {
System.out.println("Connected to database!");
}
}
Chcę, żeby po naciśnięciu przycisku uruchamiała się klasa Connect, do której przekazane zostaną zmienne login i password z klasy Interface. Nie wiem tylko jak mam przekazać zmienne.