Я построил jframe, но когда я нажимаю на кнопку, чтобы перейти к другому кадру, ничего не происходит, даже если не выдается никаких ошибок. Я использовал addActionListener, actionPerformed и setVisible (true) для экземпляра второго jframe.
вот мой код:
public class JhomeMain extends JFrame {
private JPanel contentPane;
private JTextField txtNameOfCoupon;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JLabel lblNameOfProduct;
private JLabel lblDiscountRate;
private JLabel lblValidDays;
private JLabel lblValidationStatus;
private JButton btnNewButton;
private JButton btnView;
private JLabel lblNewLabel_1;
private JLabel lblNewLabel_2;
private JTextField textField_4;
private JLabel lblNewLabel_3;
private JLabel lblNewLabel_4;
private JLabel lblNewLabel_5;
/**
* Launch the application.
*/
Основной метод здесь
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
JhomeMain frame = new JhomeMain();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
/**
* Create the frame.
*/
public JhomeMain() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 970, 655);
contentPane = new JPanel();
contentPane.setBackground(new Color(135, 206, 250));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
lblNewLabel_3 = new JLabel("Coupons Processing System");
lblNewLabel_3.setBounds(324, 10, 266, 22);
lblNewLabel_3.setFont(new Font("Lucida Grande", Font.BOLD, 18));
contentPane.add(lblNewLabel_3);
// ...
Вот проблемная часть ниже:
Start
btnView = new JButton("View");
btnView.setBounds(584, 545, 82, 29);
contentPane.add(btnView);
btnNewButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//closing the current window
//frame.dispose();
Jsecond second = new Jsecond();
second.setVisible(true);
}
});
}
Конец проблемной части