三天写一个Java demo_初学Java 写的一个简陋的Swing Demo

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.border.BevelBorder;

import javax.swing.border.Border;

public class ConnectView extends JFrame implements ActionListener {

public static final int ROW = 8;

public static final int COLUMN = 8;

public static final int hi = 2;

public static final int vi = 2;

private JButton about;

public JButton[] jbutton;

private JLabel jlabel;

private Font font;

public ConnectView() {

font = new Font("宋体", Font.BOLD, 36);

jlabel = new JLabel("用户区");

about = new JButton("关于本游戏引擎");

jbutton = new JButton[ROW * COLUMN];

GridLayout gridlayout = new GridLayout(ROW, COLUMN);

this.setSize(800, 600);

this.setVisible(true);

this.setResizable(false);

this.setTitle("ConnectView-祖国");

Color highlightInner = new Color(145, 123, 23);

Color highlightOuter = new Color(0, 128, 255);

Color shadowOuter = new Color(0, 128, 255);

Color shadowInner = new Color(45, 204, 23);

Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED,

highlightOuter, highlightInner, shadowOuter, shadowInner);

JPanel jpl_top = new JPanel();

jpl_top.setBorder(border);

// jpl_top.setBackground(Color.cyan);

jpl_top.setPreferredSize(new Dimension(800, 60));

about.setPreferredSize(new Dimension(150, 30));

jpl_top.add(about);

about.addActionListener(this);

JPanel jpl_center = new JPanel();

jpl_center.setBackground(new Color(98, 171, 202));

jpl_center.setBorder(border);

jpl_center.setPreferredSize(new Dimension(600, 540));

jpl_center.setLayout(gridlayout);

for (int i = 0; i < ROW * COLUMN; i++) {

jbutton[i] = new JButton("me");

jbutton[i].setActionCommand("" + i);

jpl_center.add(jbutton[i]);

jbutton[i].addActionListener(this);

}

JPanel jpl_east = new JPanel();

// jpl_east.setBackground(Color.green);

jpl_east.setBorder(border);

jpl_east.setPreferredSize(new Dimension(200, 540));

jpl_east.add(jlabel, BorderLayout.WEST);

jlabel.setForeground(Color.blue);

jlabel.setFont(font);

Clock clock = new Clock();

jpl_top.add(clock);

this.getContentPane().add(jpl_top, "North");

this.getContentPane().add(jpl_center, "Center");

this.getContentPane().add(jpl_east, "East");

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new ConnectView();

}

@Override

public void actionPerformed(ActionEvent e) {

if (e.getSource() == about) {

System.out.println("me pressed");

String message = "This is created by SINQS 2010-09-27";

JOptionPane.showMessageDialog(about, message, "关于",

JOptionPane.INFORMATION_MESSAGE, new ImageIcon(

"image/about.png"));

return;

}

if (e.getSource() instanceof JButton) {

JButton jbutton = (JButton) e.getSource();

int offset = Integer.parseInt(jbutton.getActionCommand());

int row, col;

row = (Math.round(offset / COLUMN));

col = (offset - row * COLUMN);

JOptionPane.showMessageDialog(this, "ROW=" + row + "COL=" + col,

"按钮", JOptionPane.INFORMATION_MESSAGE);

jbutton.setEnabled(false);// 设置按钮不能被点击

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值