gpt4 book ai didi

java - 单击按钮打开新屏幕或页面(java-eclipse)

转载 作者:行者123 更新时间:2023-11-30 03:52:15 25 4
gpt4 key购买 nike

我有一个带有标题和一些按钮的主页,当我单击按钮时,我无法打开新窗口。这是我为主页以及下一个屏幕的类提供的代码,我试图打开修剪过的相关内容。 NewTicketWindow 类也已附加,目前它很简单。如有任何帮助,我们将不胜感激。

public class Home
{

private JFrame frame;
JInternalFrame internalFrame;

/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
Home window = new Home();
window.frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public Home()
{
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);

JLabel title1 = new JLabel("City of Murphy");

JLabel title2 = new JLabel("Traffic Ticket Input System");

JButton newTicketButton = new JButton("New Ticket");
newTicketButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{

}

});

JButton payTicketButton = new JButton("Make a Payment");

JButton reportButtton = new JButton("Ticket Report");

JButton exitButton = new JButton("Exit");
GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
}

二等舱(我想在按下新票按钮时打开的屏幕

public class NewTicketWindow extends JFrame
{

private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
NewTicketWindow frame = new NewTicketWindow();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public NewTicketWindow()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);

JLabel lblEnterNewTicket = new JLabel("Enter New Ticket Information");
GroupLayout gl_contentPane = new GroupLayout(contentPane);

}

最佳答案

只需将这些行添加到您的操作执行代码中 -

NewTicketWindow frame = new NewTicketWindow();
frame.setVisible(true);

关于java - 单击按钮打开新屏幕或页面(java-eclipse),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24147671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com