The code does not say much, the picture is self-added, the realization function has the number than the size, the menu starts, the Help, exits, about and so on, the running result
Import Java.awt.BorderLayout;
Import Java.awt.Color;
Import Java.awt.FlowLayout;
Import Java.awt.Font;
Import Java.awt.GridLayout;
Import Java.awt.Image;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Java.util.Random;
Import Javax.swing.ImageIcon;
Import Javax.swing.JButton;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
Import Javax.swing.JMenu;
Import Javax.swing.JMenuBar;
Import Javax.swing.JMenuItem;
Import Javax.swing.JOptionPane;
Import Javax.swing.JPanel;
Import Javax.swing.JTextField;
public class Bingo extends JFrame implements ActionListener {
JFrame frame;
JMenuBar Topbbr;
JMenu Menuq;
JMenu Menuf;
JMenuItem start = new JMenuItem ("Start (n)");
JMenuItem out = new JMenuItem ("No Play (e)");
JMenuItem help = new JMenuItem ("Assist (h)");
JMenuItem about = new JMenuItem ("On (a)");
JPanel Panelmain = new JPanel (new BorderLayout ());
JPanel panelnext = new JPanel (new BorderLayout ());
JButton btnstart;
JPanel Jp1, JP2, JP3, JP4;
public static void Main (string[] args) {
New Bingo ();
}
Public Bingo () {
frame = new JFrame ();
TOPBBR = new JMenuBar ();
Frame.settitle ("Wang's Guess Number Game 1.0 edition");
Frame.setsize (400, 320);
Frame.setlocation (450, 240);
Frame.setlayout (GetLayout ());
Frame.setlayout (New FlowLayout ());
Menuq = new JMenu ("Game (q)");
Menuq.add (start);
Menuq.add (out);
Menuf = new JMenu ("Help (f)");
ImageIcon icon = new ImageIcon ("imgs/logo.jpg");
btnstart = new JButton (icon);
JButton Caibutton = new JButton ("Guess a guess");
JButton Congbutton = new JButton ("Re-Come");
JTextField Text = new JTextField (6);
JLabel mes = new JLabel ("Please enter a 2-digit number");
Menuf.add (Help);
Menuf.add (about);
Topbbr.add (Menuq);
Topbbr.add (MENUF);
Frame.setjmenubar (TOPBBR);
Panelmain.add ("Center", btnstart);
Frame.add (Panelmain);
Frame.setresizable (FALSE);
Frame.setvisible (TRUE);
Image im = new ImageIcon ("Imgs/logo.jpg"). GetImage ();
im = Im.getscaledinstance ( -1, do_nothing_on_close);
Seticonimage (IM);
Start.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Panelmain.setvisible (FALSE);
Start.setenabled (FALSE);
Frame.add (Panelnext);
JP1 = new JPanel ();
JP2 = new JPanel (New GridLayout (2, 1));
JP3 = new JPanel ();
JLabel top = new JLabel ("??");
Top.setbackground (New Color (100, 100, 0, 100));
Top.setopaque (TRUE);
JLabel JB = new JLabel ("");
JLabel jb2 = new JLabel (
" ");
Top.setfont (New Font ("Sandi", Font.Bold, 100));
Top.setforeground (Color.yellow);
Jp1.add (top);
Jp2.add (MES);
Jp2.add (text);
Jp3.add (Caibutton);
Jp3.add (Congbutton);
Panelnext.add ("North", JP1);
Panelnext.add ("Center", JP2);
Panelnext.add ("West", JB);
Panelnext.add ("East", JB2);
Panelnext.add ("South", JP3);
Panelnext.setvisible (TRUE);
}
});
Start listening 1
Btnstart.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Start.setenabled (FALSE);
Panelmain.setvisible (FALSE);
Frame.add (Panelnext);
JP1 = new JPanel ();
JP2 = new JPanel (New GridLayout (2, 1));
JP3 = new JPanel ();
JLabel top = new JLabel ("??");
Top.setbackground (New Color (100, 100, 0, 100));
Top.setopaque (TRUE);
JLabel JB = new JLabel ("");
JLabel jb2 = new JLabel ("");
Top.setfont (New Font ("Sandi", Font.Bold, 100));
Top.setforeground (Color.yellow);
Jp1.add (top);
Jp2.add (MES);
Jp2.add (text);
Jp3.add (Caibutton);
Jp3.add (Congbutton);
Panelnext.add ("North", JP1);
Panelnext.add ("Center", JP2);
Panelnext.add ("West", JB);
Panelnext.add ("East", JB2);
Panelnext.add ("South", JP3);
Panelnext.setvisible (TRUE);
}
});
Exit monitoring
Out.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Frame.setvisible (FALSE);
}
});
Help monitor
Help.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Joptionpane.showmessagedialog (NULL, "Please press to start the game!") Just guess the numbers, don't say more! ",
"Help", joptionpane.plain_message);
}
});
About monitoring
About.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Joptionpane.showmessagedialog (frame, "Thank you for tasting the face!") "," 3Q ",
Joptionpane.warning_message);
}
});
Start listening 2
Caibutton.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Random x = new Random ();
int y = x.nextint (100);
try {
int num = Integer.parseint (Text.gettext ());
if (num > y) {
Mes.settext ("You entered the" + num + "big Oh!") ");
if (num > 99) {
Mes.settext ("Please enter a number less than 99!");
}
}else if (num = = y) {
Mes.settext ("Congratulations, you guessed it!") ");
}
else{
Mes.settext ("You entered the" + num + "small Oh!") ");
if (num < 1) {
Mes.settext ("Please enter a number greater than 0!");
}
}
} catch (Exception E2) {
Mes.settext ("Please enter a number of 0-99!");
}
}
});
Reset Monitoring
Congbutton.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
Text.settext ("");
}
});
}
@Override
public void actionperformed (ActionEvent e) {
}
}
Java guessing numbers game