我需要一些帮助,使用Eclipse来实现一个Jbutton任务/代码,当我点击它时会打开另一个applet,就像游戏发射器有" Play Game"启动游戏的选项。这可能吗?
我的源代码:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
public class NiceGui {
private JFrame frmSomegame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
NiceGui window = new NiceGui();
window.frmSomegame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public NiceGui() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmSomegame = new JFrame();
frmSomegame.setTitle("SomeGame");
frmSomegame.getContentPane().setBackground(Color.BLUE);
frmSomegame.setBounds(100, 100, 450, 300);
frmSomegame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmSomegame.getContentPane().setLayout(null);
JButton btnNewButton = new JButton("Play");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null,"Hello!");
}
});
btnNewButton.setBounds(28, 41, 133, 50);
frmSomegame.getContentPane().add(btnNewButton);
JButton btnNewButton_1 = new JButton("Credit");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null,"Created by Calvin");
}
});
btnNewButton_1.setBounds(25, 142, 136, 50);
frmSomegame.getContentPane().add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("Quit");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int result = JOptionPane.showConfirmDialog(null,"Do you want to quit?","Are you sure?",JOptionPane.YES_NO_OPTION) ;
if(result == JOptionPane.YES_OPTION) {
System.exit(0) ;
}
}
});
btnNewButton_2.setBounds(249, 142, 156, 50);
frmSomegame.getContentPane().add(btnNewButton_2);
}
}