package com.lovo.twoday;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Toolkit;
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.JTextField;
public class Homework1 extends JFrame {
private Container conts = this.getContentPane(); // 中间容器
private JLabel isLab;// 用户名标签
private JTextField isTxt;
private JLabel pngLab;
private JButton guessBtn; // 按钮
private JButton cancelBtn;
private JMenuBar menuBar;// 菜单栏
private JMenu gameMenuItem;// 第一层的第一个菜单
private JMenu helpMenuItem;
public Homework1() {
Toolkit tk = Toolkit.getDefaultToolkit(); // 工具类
this.setSize(400, 500); // 窗体大小
// 设置窗体大小不可更改
this.setResizable(false);
this.setIconImage(tk.createImage("img/hp.JPG")); // 设置窗体图标
this.setTitle("Let‘s Play HiLo"); // 设置窗体的标题
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置窗体关闭即为关闭程序
this.setLocationRelativeTo(null); // 窗体位置
this.contentP();
this.setVisible(true); // 窗体可见 }
public void contentP() {
// 设置容器的布局管理器为空---空布局管理
this.conts.setLayout(null);
// 设置窗体面板的背景色
this.conts.setBackground(Color.WHITE);
this.isLab = new JLabel();
this.isLab.setText("50 is");
this.isLab.setFont(new Font("宋体", Font.ITALIC, 18)); // 字体
this.isLab.setForeground(Color.black); // 字体颜色
this.isLab.setBounds(100, 130, 90, 30);
this.conts.add(this.isLab);
//图片
this.pngLab = new JLabel();
this.pngLab.setIcon(new ImageIcon("img/zz.png"));
this.pngLab.setBounds(160,110, 73, 71);
this.conts.add(this.pngLab);
// 文本框
this.isTxt = new JTextField();
this.isTxt.setFont(new Font("宋体", Font.ITALIC, 18));
this.isTxt.setForeground(Color.black);
this.isTxt.setBounds(120, 200, 180, 50);
this.conts.add(this.isTxt);
// 按钮
this.guessBtn = new JButton();
this.guessBtn.setText("Guess");
this.cancelBtn = new JButton();
this.cancelBtn.setText("Cance");
this.guessBtn.setFont(new Font("微软雅黑", Font.ITALIC, 12));
this.guessBtn.setForeground(Color.BLUE);
this.guessBtn.setBounds(90, 350, 100, 30);
this.conts.add(this.guessBtn);
this.cancelBtn.setFont(new Font("微软雅黑", Font.ITALIC, 12));
this.cancelBtn.setForeground(Color.BLUE);
this.cancelBtn.setBounds(210, 350, 100, 30);
this.conts.add(this.cancelBtn);
// 菜单
this.menuBar = new JMenuBar();
this.setJMenuBar(this.menuBar);
this.gameMenuItem = new JMenu("Game");
this.helpMenuItem = new JMenu("Help");
this.menuBar.add(this.gameMenuItem);
this.menuBar.add(this.helpMenuItem);
}
public static void main(String[] args) {
new Homework1();
}
}