初学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);// 设置按钮不能被点击 } } } 运行效果图: