📄 jiemian.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Jiemian implements Runnable{
public static JFrame mf=new JFrame();
MenuBar m=new MenuBar();
Menu m1=new Menu("游戏");
Menu m2=new Menu("帮助");
MenuItem mm1=new MenuItem ("退出");
MenuItem mm2=new MenuItem ("游戏记录");
MenuItem mm3=new MenuItem ("游戏规则");
MenuItem mm4=new MenuItem ("关于");
ImageIcon SetupImage=new ImageIcon("src\\dd\\board.jpg");
JPanel one=new JPanel();
JPanel two=new JPanel(new BorderLayout());
JPanel three=new JPanel();
JPanel four=new JPanel();
JPanel five=new JPanel();
JPanel six=new JPanel();
JButton b1=new JButton("开始",SetupImage);
JLabel l1 =new JLabel("grade");
JLabel l2 =new JLabel("level");
JLabel l3 =new JLabel("speed");
JTextField t1=new JTextField("",8);
JTextField t2=new JTextField("",6);
JTextField t3=new JTextField("",6);
Graphics g;
public void run(){
mf.setMenuBar(m);
m.add(m1);
m.add(m2);
m1.add(mm2);
m1.add(mm1);
m2.add(mm3);
m2.add(mm4);
l1.setFont(new Font("Serif", Font.BOLD, 22));
l1.setForeground(Color.orange);
l2.setFont(new Font("Serif", Font.BOLD, 20));
l2.setForeground(Color.CYAN);
l3.setFont(new Font("Serif", Font.BOLD, 20));
l3.setForeground(Color.CYAN);
b1.setForeground(Color.orange);
t1.setForeground(Color.cyan);
t1.setBackground(Color.gray);
t1.setFont(new Font("Serif", Font.BOLD, 15));
t2.setForeground(Color.yellow);
t2.setBackground(Color.gray);
t2.setFont(new Font("Serif", Font.BOLD, 15));
t3.setForeground(Color.yellow);
t3.setBackground(Color.gray);
t3.setFont(new Font("Serif", Font.BOLD, 15));
b1.setBackground(Color.darkGray);
one.setSize(500,50);
two.setSize(300,400);
three.setSize(500,50);
four.setSize(110,290);
five.setSize(90,400);
six.setSize(110,130);
one.setBackground(Color.black);
two.setBackground(Color.gray);
three.setBackground(Color.black );
four.setBackground(Color.black );
five.setBackground(Color.black );
six.setBackground(Color.black);
one.setLocation(0,0);
two.setLocation(90,50);
// ii.setLocation(90,50);
three.setLocation(0,450);
four.setLocation(390, 180);
five.setLocation(0, 50);
six.setLocation(390, 50);
mf.setLayout(null);
mf.add(one);
mf.add(two);
mf.add(three);
mf.add(four);
mf.add(five);
mf.add(six);
six.add(l2);
six.add(t2);
six.add(l3);
six.add(t3);
six.setLayout(new FlowLayout(FlowLayout.RIGHT));
three.add(b1);
one.add(l1);
one.add(t1);
two.add(new MyPane(new ImageIcon("src\\dd\\mm.jpg")));
mm1.addActionListener(new h5());
mm2.addActionListener(new h2());
mm3.addActionListener(new h3());
mm4.addActionListener(new h4());
b1.addActionListener(new h1());
mf.setResizable(false);
mf.setLocation(350,150);
mf.setSize(505,555);
mf.setBackground(Color.black);
mf.setVisible(true);
}
public static void main(String arg[]){
new Jiemian().run();
}
class MyPane extends JPanel {
private ImageIcon image = null; // 要画的图形
public MyPane(ImageIcon image) {
this.image = image;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image.getImage(), 0, 0, 300, 400, this); // 将固定大小的Image画到固定的位置
}
}
public class h1 implements ActionListener{
//游戏开始
public void actionPerformed(ActionEvent e) {
}
}
public class h2 implements ActionListener{
//游戏记录
public void actionPerformed(ActionEvent e) {
}
}
public class h3 implements ActionListener{
//游戏规则
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "游戏规则:\n 1 避过对面开来的车\n 2 用上下左右键控制车的移动 \n3 可以用PAGE_UP跳跃躲过\n" +
"4 每躲过六辆车跳跃次数加1" +"游戏规则", null, JOptionPane.INFORMATION_MESSAGE);
}
}public class h4 implements ActionListener{
//关于
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "本程序由信二嘻嘻哈哈工作小组制作", null, JOptionPane.INFORMATION_MESSAGE);
}
}
public class h5 implements ActionListener{
//退出
public void actionPerformed(ActionEvent e) {
int st=JOptionPane.showConfirmDialog(null, "确定要退出吗?",null, JOptionPane.YES_NO_OPTION);
if (st == JOptionPane.NO_OPTION)
return;
System.exit(0);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -