- 博客(0)
- 资源 (2)
- 收藏
- 关注
Java 版蛋疼游戏,开发工具:MyEclipse
开发工具:MyEclipse
将下面的图片添加到MyEclipse的src文件夹下,第一幅图片名1.gif,第二幅图片名4.gif
===================================================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FirstFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
JDialog jd;
JButton jb;
ImageIcon a; //插入图片
JLabel jl,jl1,jl2;
SecondFrame jf2;
public FirstFrame(){
Container wc=this.getContentPane();
wc.setLayout(null);
a=new ImageIcon("src/1.gif"); //插入图片
jb=new JButton(a);
jb.setBounds(45,45,410,160);
jb.addActionListener(this);
wc.add(jb);
jl=new JLabel("点击上面的动感水果人,进入少林水果六人阵!");
jl.setBounds(120,230,280,20);
jl.setForeground(Color.BLUE);
wc.add(jl);
jl1=new JLabel("这是一个具有挑战的窗口游戏,相信你会玩得很开心!");
jl1.setBounds(100,300, 320, 20);
jl1.setForeground(Color.RED);
wc.add(jl1);
jl2=new JLabel("让我们开始挑战吧!");
jl2.setBounds(200,320,130, 20);
jl2.setForeground(Color.RED);
wc.add(jl2);
this.setTitle("蛋疼游戏 1.0版");
this.setUndecorated(true);
this.setSize(500, 400);
this.setLocationRelativeTo(null); //让窗口居中
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e){
jf2=new SecondFrame();
jf2.windows2();
jf2.Realize();
this.setVisible(false);
}
}
//第一个窗体
===================================================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SecondFrame extends JFrame implements ActionListener,WindowListener {
JLabel jl;
JButton jb;
ThirdFrame jf3;
private static final long serialVersionUID = 2L;
public void windows2(){
this.setUndecorated(true); // 去掉窗口的装饰
this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); // 设置这个只有关闭按钮,禁止最大化按钮,同时还能实现最大化。
this.setTitle("第一关");
this.setSize(500, 400);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.addWindowListener(this);
}
public void Realize(){
Container wc=this.getContentPane();
wc.setLayout(null);
jl=new JLabel("这是第一关想办法找到第二关的入口");
jl.setBounds(130, 90, 500, 50);
jl.setForeground(Color.BLUE);
wc.add(jl);
jb=new JButton("第二关入口");
jb.setBounds(300, 500, 100, 30);
jb.setForeground(Color.BLUE);
jb.addActionListener(this);
wc.add(jb);
}
public void actionPerformed(ActionEvent e) {
jf3=new ThirdFrame();
jf3.windows3();
jf3.Realize();
this.setVisible(false);
}
@Override
public void windowActivated(WindowEvent e) {}
@Override
public void windowClosed(WindowEvent e) {}
@Override
public void windowClosing(WindowEvent e) {
JOptionPane.showMessageDialog(null, " 修行不够!!闯关失败!!!", "失败!!!", 2);
}
@Override
public void windowDeactivated(WindowEvent e) {}
@Override
public void windowDeiconified(WindowEvent e) {}
@Override
public void windowIconified(WindowEvent e) {}
@Override
public void windowOpened(WindowEvent e) {}
}
//第二个窗体
............................
2010-12-01
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人