import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;public class Gui extends JFrame implements ActionListener {
static SouthPanel sp;
static SetFrame sf;
JMenuItem newgame;
JMenuItem level;
JMenuItem appearance;
JMenuItem recordinfo;
JMenuItem exit;
JMenuItem about;
JMenuItem method;
MyJButton jb[][];
public static HashSet hs;// 用于保存生成的随机炸弹数列
public static boolean lasted = false; // 标志变量 标记是否重新开始新的游戏
JPanel main; Gui() {
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setResizable(false);
sp = new SouthPanel();
MyMouseListenerAdapter.noBoundnum = 0; // 每次雷区初始化都重新设定noBoundnum的数值为0
// (该变量用于判断扫雷是否成功)
JMenuBar jmenubar = new JMenuBar();
JMenu game = new JMenu("游戏");
JMenu help = new JMenu("帮助");
newgame = new JMenuItem("新游戏"); newgame.addActionListener(this); game.add(new JSeparator()); level = new JMenuItem("级别"); level.addActionListener(this); recordinfo = new JMenuItem("统计信息"); recordinfo.addActionListener(this); appearance = new JMenuItem("更改外观"); appearance.addActionListener(this); exit = new JMenuItem("退出"); exit.addActionListener(this); about = new JMenuItem("关于扫雷"); about.addActionListener(this); method = new JMenuItem("玩法"); method.addActionListener(this); game.add(newgame);
game.add(level);
game.add(recordinfo);
game.add(appearance);
game.add(exit); help.add(about);
help.add(method); jmenubar.add(game);
jmenubar.add(help);
this.setJMenuBar(jmenubar); System.out.println("in init");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jb = new MyJButton[sf.setheight + 1][sf.setwidth + 1];
// 初始化小 默认为简单模式 // ....................初始化炸弹...................................
initBound(Gui.lasted);// 调用函数初始化炸弹!! main = new JPanel();
main.setBackground(Color.CYAN);
int num = 0;
main.setLayout(new GridLayout(sf.setheight, sf.setwidth));
for (int i = 1; i <= sf.setheight; i++) {
for (int j = 1; j <= sf.setwidth; j++) {
if (jb[i][j] == null) {
jb[i][j] = new MyJButton(i, j);
num++;
} jb[i][j].addMouseListener(new MyMouseListenerAdapter(this));
main.add(jb[i][j]); // 从第二个元素开始赋值!!
}
System.out.println("再设定 " + num + "个元素!"); }
for (int i = 1; i <= sf.setheight; i++) {
for (int j = 1; j <= sf.setwidth; j++) {
if (!jb[i][j].haveimage) {
jb[i][j].num = seekAllBound(i, j);
}
}
} this.add(main, BorderLayout.CENTER);
// this.add(arg0, arg1) sp.time.setText("" + SetBound.number * 6 + "");
sp.bound.setText("" + SetBound.number + "");
// 创建面板
this.add(sp.jp, BorderLayout.SOUTH); this.setBounds(100, 100, 44 * sf.setwidth, 44 * sf.setheight + 30);
this.setVisible(true);
PlayAudio.playstart(); } public void initBound(boolean lasted) {
if (!lasted) {
hs = SetBound.initBound(this.sf.setwidth, this.sf.setheight);
}
Iterator it = hs.iterator();
int count = 1;
while (it.hasNext()) {
int location = (Integer) it.next();
int hang;
int lie;
if (location % this.sf.setwidth != 0) {
hang = location / this.sf.setwidth + 1;
lie = location % this.sf.setwidth; } else {
hang = location / this.sf.setwidth;
lie = this.sf.setwidth;
}
this.jb[hang][lie] = new MyJButton(hang, lie);
this.jb[hang][lie].haveimage = true;
// 设置初始炸弹!!(给某些MJButton设置背景图片!!) System.out.println("设置了" + count++ + "个 行为 " + hang + " 列为 " + lie); } } public void select(int height, int width) { // 设置标志 MyMouseListenerAdapter的over为false!!
MyMouseListenerAdapter.over = false;
if (MyMouseListenerAdapter.timer != null) {
MyMouseListenerAdapter.timer.cancel();
MyMouseListenerAdapter.timer = null; // 取消正在进行的倒计时!
}
Random ran = new Random();
this.getContentPane().removeAll(); // 清空上次的面板!!
this.sf.setwidth = width;
this.sf.setheight = height;
jb = new MyJButton[height + 1][width + 1]; initBound(lasted);// 调用函数初始化炸弹!! main = new JPanel();
main.setBackground(Color.CYAN);
int num = 0;
main.setLayout(new GridLayout(sf.setheight, sf.setwidth));
for (int i = 1; i <= sf.setheight; i++) {
for (int j = 1; j <= sf.setwidth; j++) {
if (jb[i][j] == null) {
jb[i][j] = new MyJButton(i, j);
num++;
} jb[i][j].addMouseListener(new MyMouseListenerAdapter(this));
main.add(jb[i][j]); // 从第二个元素开始赋值!!
} }
for (int i = 1; i <= sf.setheight; i++) {
for (int j = 1; j <= sf.setwidth; j++) {
if (!jb[i][j].haveimage) {
jb[i][j].num = seekAllBound(i, j);
}
}
} this.add(main, BorderLayout.CENTER);
// 创建面板
if (sp == null) {
System.out.println("南部面板没有创建成功!程序返回!");
return;
}
JPanel southJpanel = sp.jp;
sp.time.setText("" + SetBound.number * 6);
sp.bound.setText("" + SetBound.number);
this.add(southJpanel, BorderLayout.SOUTH); int extraheight;
int extrawidth;
extrawidth = (Integer) (width * 30 / 6);
extraheight = (Integer) (height * 10 / 6); ((FlowLayout) southJpanel.getLayout()).setHgap(extrawidth);
((FlowLayout) southJpanel.getLayout()).setVgap(extraheight); this.setBounds(100, 100, 44 * sf.setwidth, 44 * sf.setheight + 30);
this.setVisible(true);
PlayAudio.playstart(); } public int seekAllBound(int height, int width) {
System.out.println("进入seekAllBound!");
int num = 0;
// 判断上一行三个元素是否为炸弹!!
if (height - 1 >= 1) {
if (width - 1 >= 1) {
if (jb[height - 1][width - 1].haveimage)
num++;
}
if (jb[height - 1][width].haveimage) {
num++;
}
if (width + 1 <= this.sf.setwidth) {
if (jb[height - 1][width + 1].haveimage) {
num++;
}
}
} // 判断左右两个元素是否为炸弹!
if (width - 1 >= 1) {
if (this.jb[height][width - 1].haveimage) {
num++;
} } if (width + 1 <= this.sf.setwidth) {
if (this.jb[height][width + 1].haveimage) {
num++;
}
}
// 判断下一行三个元素是否是炸弹
if (height + 1 <= this.sf.setheight) {
if (width - 1 >= 1) {
if (this.jb[height + 1][width - 1].haveimage) {
num++;
}
}
if (this.jb[height + 1][width].haveimage) {
num++;
}
if (width + 1 <= this.sf.setwidth) {
System.out.println(this.jb[height + 1][width + 1].hang);
if (this.jb[height + 1][width + 1].haveimage) {
num++;
}
}
}
return num;// 返回周围炸弹的数量! } public void actionPerformed(ActionEvent e) {
if (e.getSource() == newgame) {
this.select(this.sf.setheight, this.sf.setwidth);
}
if (e.getSource() == level) { if (Gui.sf == null) {
System.out.println("null!");
sf = new SetFrame(this);
} else {
if (!Gui.sf.isVisible()) {
Gui.sf.setVisible(true);
}
} }
if (e.getSource() == recordinfo) { } if (e.getSource() == appearance) { // 更改按钮的外观
if (this.jb == null) {
return;
}
if (!MyJButton.changeColor) {
MyJButton.color = new Color(150, 150, 250); } else {
MyJButton.color = new Color(100, 200, 100);
}
MyJButton.changeColor = !MyJButton.changeColor; this.setBackground(MyJButton.color); for (int i = 1; i <= this.sf.setheight; i++) { for (int j = 1; j <= this.sf.setwidth; j++) { jb[i][j].setBackground(MyJButton.color);
}
}
}
if (e.getSource() == exit) {
this.dispose();
}
if (e.getSource() == about) { JOptionPane.showMessageDialog(this,
"QQ : 928229202\n Date:2011/09/01", "关于扫雷",
JOptionPane.INFORMATION_MESSAGE, null); }
if (e.getSource() == method) {
JOptionPane
.showMessageDialog(
this,
"鼠标右键标示雷 标示后的雷再次鼠标点击是安全的\n被标示后的雷,再次鼠标右击则处于危险的\n危险中的雷左击如果是雷则游戏结束\n游戏以点开所有的非雷标志胜利\n注意有时间限制哦!");
} } public static void main(String[] args) {
Gui gui = new Gui(); }}
解决方案 »
- 父类有个静态变量name,那子类可以命名一个变量叫name吗?
- laughsmile(海边的星空)和test1234()请进(偶给你俩个人加分。。。)
- 用户login的错误的测试
- 将字符串写入.txt文件问题!
- 求助!!!如何用Swing组件来实现这样一个命令行模式中的功能啊?(有代码)
- 大哥们,救救急,怎么回事???
- 我正在赶往程序员的途中。。。途中迷茫。。彷徨。。失去方向 想哥哥们能带我达到目的地 5555555555555555555555555555555555555555555555
- 求 Java核心技术卷二(新版) 源代码,收到代码后高分相送!
- 请问怎样用JAVA给文件加密!!!,急!
- 帮我看看这段程序!
- 如何打jar包
- 这段代码是线程安全的吗?
import java.awt.event.MouseEvent;
import java.util.Timer;
import java.util.TimerTask;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;public class MyMouseListenerAdapter extends MouseAdapter {
Gui gui;
static Timer timer;
public static int noBoundnum = 0;
public static ImageIcon image = new ImageIcon("image\\4.gif");
public static int rightCount;
public static boolean over = false; public MyMouseListenerAdapter(Gui gui) {
this.gui = gui;
} public void mouseClicked(MouseEvent e) {
// 第一次点击 开始时间倒计时
if (timer == null) {
MyMouseListenerAdapter.startTimer();
System.out.println("null");
} if (e.getButton() == MouseEvent.BUTTON1) { MyJButton mj = (MyJButton) e.getSource();
mj.setState(true);// 防止递归死循环 标示按钮已经递归过!!
if (mj.show) {// 如果显示了旗帜 则对左键点击无反应
return;
}
if (mj.haveimage) {// 清空显示所有按钮的雷和数字!!
this.guiclear();
return;
}
mj.init();// 透明显示按钮上的数字!
if (MyMouseListenerAdapter.noBoundnum
% (this.gui.sf.setwidth * this.gui.sf.setheight - SetBound.number) == 0
&& over == false) {
// 非雷数量正确 扫描完成
// 弹出扫描成功对话框!!
over = true;
PlayAudio.playswin();
this.timer.cancel();
JOptionPane.showMessageDialog(this.gui, "恭喜你,你赢了!!"); } if (mj.num == 0) {
if (mj.state)
Digui(((MyJButton) e.getSource()).hang, ((MyJButton) e
.getSource()).lie); // 上面三个元素 }
} if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
((MyJButton) e.getSource())
.setShow(!((MyJButton) e.getSource()).show);
if (((MyJButton) e.getSource()).show) {
((JButton) e.getSource()).setIcon(image);
} else {
((JButton) e.getSource()).setIcon(null);
} } } public void Digui(int hang, int lie) { // 上面三个元素
if (hang - 1 >= 1) {
if (lie - 1 >= 1) {
if (!this.gui.jb[hang - 1][lie - 1].initflag) {
this.gui.jb[hang - 1][lie - 1].init();
} if (this.gui.jb[hang - 1][lie - 1].num == 0) {
if (this.gui.jb[hang - 1][lie - 1].state) {
this.gui.jb[hang - 1][lie - 1].setState(false);
Digui(hang - 1, lie - 1);
} }
}
if (!this.gui.jb[hang - 1][lie].initflag) {
this.gui.jb[hang - 1][lie].init();
}
if (this.gui.jb[hang - 1][lie].num == 0) {
if (this.gui.jb[hang - 1][lie].state) {
this.gui.jb[hang - 1][lie].setState(false);
Digui(hang - 1, lie);
} }
if (lie + 1 <= this.gui.sf.setwidth) {
if (!this.gui.jb[hang - 1][lie + 1].initflag) {
this.gui.jb[hang - 1][lie + 1].init();
}
if (this.gui.jb[hang - 1][lie + 1].num == 0) {
if (this.gui.jb[hang - 1][lie + 1].state) {
this.gui.jb[hang - 1][lie + 1].setState(false);
Digui(hang - 1, lie + 1);
} } } } // 前后两个元素
if (lie - 1 >= 1) {
// System.out.println("左边元素");
if (!this.gui.jb[hang][lie - 1].initflag) {
this.gui.jb[hang][lie - 1].init();
}
if (this.gui.jb[hang][lie - 1].num == 0) {
if (this.gui.jb[hang][lie - 1].state) {
this.gui.jb[hang][lie - 1].setState(false);
Digui(hang, lie - 1);
} }
}
if (lie + 1 <= this.gui.sf.setwidth) {
if (!this.gui.jb[hang][lie + 1].initflag) {
this.gui.jb[hang][lie + 1].init();
}
if (this.gui.jb[hang][lie + 1].num == 0) {
if (this.gui.jb[hang][lie + 1].state) {
this.gui.jb[hang][lie + 1].setState(false);
Digui(hang, lie + 1);
} }
} // 下面三个元素 if (hang + 1 <= this.gui.sf.setheight) {
if (lie - 1 >= 1) {
if (!this.gui.jb[hang + 1][lie - 1].initflag) {
this.gui.jb[hang + 1][lie - 1].init();
}
if (this.gui.jb[hang + 1][lie - 1].num == 0) {
if (this.gui.jb[hang + 1][lie - 1].state) {
this.gui.jb[hang + 1][lie - 1].setState(false);
Digui(hang + 1, lie - 1);
} }
}
if (!this.gui.jb[hang + 1][lie].initflag) {
this.gui.jb[hang + 1][lie].init();
}
if (this.gui.jb[hang + 1][lie].num == 0) {
if (this.gui.jb[hang + 1][lie].state) {
this.gui.jb[hang + 1][lie].setState(false);
Digui(hang + 1, lie);
} }
if (lie + 1 <= this.gui.sf.setwidth) {
if (this.gui.jb[hang + 1][lie + 1].initflag) {
this.gui.jb[hang + 1][lie + 1].init();
}
if (this.gui.jb[hang + 1][lie + 1].num == 0) {
if (this.gui.jb[hang + 1][lie + 1].state) {
this.gui.jb[hang + 1][lie + 1].setState(false);
Digui(hang + 1, lie + 1);
} }
} } } public static void startTimer() {
if (MyMouseListenerAdapter.timer == null) {
MyMouseListenerAdapter.timer = new Timer();
MyMouseListenerAdapter.timer.scheduleAtFixedRate(new MyTimerTask(),
500, 1000);
}
} public void guiclear() {
this.timer.cancel();// 先暂停计时器 然后清空显示界面!
for (int i = 1; i <= this.gui.sf.setheight; i++) { for (int j = 1; j <= this.gui.sf.setwidth; j++) {
if (this.gui.jb[i][j].haveimage) {
this.gui.jb[i][j].setContentAreaFilled(false); // 设置背景色未null
// 即透明。
this.gui.jb[i][j].setBorder(null);
this.gui.jb[i][j].setIcon(new ImageIcon("./image/1.gif"));
} else {
this.gui.jb[i][j].init();
}
}
}
JOptionPane.showMessageDialog(this.gui, "踩到雷了,扫雷失败!"); Object[] options = { "退出", "重新开始这个游戏", "再玩一局" };
int response = JOptionPane.showOptionDialog(this.gui, "抱歉,你踩到雷了!",
"游戏失败", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
System.out.println(" afsfsdfsdf " + response);
if (response == 0) {
this.gui.dispose();
} else if (response == 1) {
this.gui.lasted = true;
this.gui.select(this.gui.sf.setheight, this.gui.sf.setwidth);
this.gui.lasted = false; } else if (response == 2) {
this.gui.lasted = false;
this.gui.select(this.gui.sf.setheight, this.gui.sf.setwidth);
} } public static void main(String[] args) {
Gui gui = new Gui();
MyMouseListenerAdapter mmla = new MyMouseListenerAdapter(gui);
}
}class MyTimerTask extends TimerTask {
public void run() {
int number = Integer.parseInt(Gui.sp.time.getText());
if (--number == 0) {
System.out.println("time is overing!");
JOptionPane.showMessageDialog(null, "很抱歉,时间到了!");
this.cancel();
} Gui.sp.time.setText("" + number);
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;public class MyJButton extends JButton { /**
* @param args
*/
public int num;
public boolean state = true; // 标志某个按钮的递归状态~~ 防止递归死循环!!(你调用我 我调用你)
public boolean initflag = false; // 标志该按钮是否被透明 主要用于判断是否扫雷最后成功!
public int hang;
public int lie;
public static ImageIcon image;
public boolean haveimage = false;
public static Color color = new Color(100, 200, 100);
public static boolean changeColor = false;
public boolean show = false; // 对应在每次对某个按钮右键点击时设置显示图片与否!! MyJButton() { super();
this.setHang(1);
this.setLie(1); } MyJButton(int hang, int lie) { super();
this.setHang(hang);
this.setLie(lie);
this.setBackground(MyJButton.color);
System.out.println(hang + "行" + lie + "列" + "的元素"); } public ImageIcon getImage() {
return image;
} public void setImage(ImageIcon image) {
this.image = image;
} public int getNum() {
return this.num;
} public void setNum(int num) {
this.num = num;
} public boolean isShow() {
return show;
} public void setShow(boolean show) {
this.show = show;
} public void init() { // 重绘调用!
if (!this.initflag) {
System.out.println(++MyMouseListenerAdapter.noBoundnum + " 个雷!");
}
this.initflag = true;
if (this.num == 0) {
this.setText(null);
} else {
this.setText(Integer.toString(this.num));
} this.setContentAreaFilled(false); // 设置背景色未null 即透明。 } public int getHang() {
return hang;
} public void setHang(int hang) {
this.hang = hang;
} public int getLie() {
return lie;
} public void setLie(int lie) {
this.lie = lie;
} public boolean isState() {
return state;
} public void setState(boolean state) {
this.state = state;
}}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;import sun.audio.AudioPlayer;
public class PlayAudio {
public static void playswin(){
InputStream inputstream;
try {
inputstream = new FileInputStream(new File("./wav/cyeah.wav"));
AudioPlayer.player.start(inputstream);
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void playstart(){
InputStream inputstream;
try {
inputstream = new FileInputStream(new File("./wav/eat.wav"));
AudioPlayer.player.start(inputstream);
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[]args){
}}
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;public class SetBound {
static int number = 9; public static HashSet initBound() {
Random ran = new Random(); HashSet<Integer> hs = new HashSet(number); while (hs.size() < number) {// 存放number个随机行列序号 hs.add(ran.nextInt(36) + 1); }
return hs; } public static HashSet initBound(int width, int height) {// 对界面产生一个随机的炸弹序列!!(用哈希集合存储)
if (width == height && width == 6) {
number = 6;
} else {
number = width * 2;// 其他模式下的炸弹数量计算!!
}
Random ran = new Random(); HashSet<Integer> hs = new HashSet(number); while (hs.size() < number) {// 存放number个随机行列序号 hs.add(ran.nextInt(width * height) + 1); }
return hs; } public static int boundnum() {
return SetBound.number;
}
}
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;public class SetFrame extends JFrame implements ActionListener {
static Gui father;
JRadioButtonMenuItem easy;
JRadioButtonMenuItem abnormal;
JRadioButtonMenuItem hard;
JRadioButtonMenuItem autoset;
JTextField widthtext;
JTextField heighttext;
JButton ensure;
JButton cancel;
public static int setwidth = 6;
public static int setheight = 6; SetFrame(Gui gui) {
this.father = gui;
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
FlowLayout fl = new FlowLayout(FlowLayout.LEFT); JPanel north = new JPanel();
north.setLayout(new FlowLayout(FlowLayout.LEFT)); ButtonGroup bg = new ButtonGroup();
easy = new JRadioButtonMenuItem("简单(6*6网格)");
easy.setSize(25, 20);
abnormal = new JRadioButtonMenuItem("正常(12*12网格)");
abnormal.setSize(25, 20);
hard = new JRadioButtonMenuItem("困难(18*18网格)");
hard.setSize(25, 20);
autoset = new JRadioButtonMenuItem("自定义((6~24)*(6~24))");
autoset.setSize(25, 20);
bg.add(easy);
bg.add(abnormal);
bg.add(hard);
bg.add(autoset); //mini.setLocation(200, 200); north.add(easy);
north.add(new JLabel(" ")); north.add(abnormal);
north.add(new JLabel(" ")); north.add(hard);
north.add(new JLabel(" ")); north.add(autoset);
//north.add(new JLabel("mini")); easy.addActionListener(this);
abnormal.addActionListener(this);
hard.addActionListener(this);
autoset.addActionListener(this); JLabel width = new JLabel(" 宽 度 :(6-20)");
width.setSize(15, 5);
widthtext = new JTextField(12);
widthtext.setSize(15, 5);
widthtext.setEditable(false);
JLabel height = new JLabel(" 高 度 :(6-20)");
height.setSize(15, 5);
heighttext = new JTextField(12);
heighttext.setEditable(false);
heighttext.setSize(15, 5);
ensure = new JButton(" 确 定");
cancel = new JButton(" 取 消"); ensure.addActionListener(this);
cancel.addActionListener(this); north.add(width);
north.add(widthtext);
north.add(height);
north.add(heighttext);
north.add(ensure);
north.add(cancel); this.add(north, BorderLayout.CENTER); this.setLocation(720, 400);
this.setSize(220, 450);
this.setVisible(true); } public void actionPerformed(ActionEvent e) {
//System.out.println("aaaa"); if (e.getSource() == easy) { this.widthtext.setEditable(false);
this.heighttext.setEditable(false); }
if (e.getSource() == abnormal) { this.widthtext.setEditable(false);
this.heighttext.setEditable(false); }
if (e.getSource() == hard) { this.widthtext.setEditable(false);
this.heighttext.setEditable(false); }
if (e.getSource() == autoset) {
if (autoset.isSelected()) {
this.widthtext.setEditable(true);
this.heighttext.setEditable(true);
} } if (e.getSource() == ensure) {
if (easy.isSelected()) {
setwidth = 6;
setheight = 6;
((Gui) this.father).select(setheight, setheight);
this.dispose();
return;
}
if (abnormal.isSelected()) {
setwidth = 12;
setheight = 12;
((Gui) this.father).select(setheight, setwidth);
this.dispose();
return;
}
if (hard.isSelected()) {
setwidth = 18;
setheight = 18;
((Gui) this.father).select(setheight, setwidth);
this.dispose();
return;
}
int Ywidth = 0;
int Yheight = 0;
try {
Ywidth = Integer.parseInt(this.widthtext.getText());
Yheight = Integer.parseInt(this.widthtext.getText());
} catch (NumberFormatException el) {
JOptionPane.showMessageDialog(this, "请输入有效数字!");
this.heighttext.setText(null);
this.widthtext.setText(null);
return;
}
if (Yheight >= 6 && Yheight <= 20 && Ywidth >= 6 && Ywidth <= 20) {
setwidth = Integer.parseInt(this.widthtext.getText());
setheight = Integer.parseInt(this.heighttext.getText());
((Gui) this.father).select(setheight, setwidth);
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "请确认高度和宽度为6-20!");
this.heighttext.setText(null);
this.widthtext.setText(null);
} }
if (e.getSource() == cancel) {
this.heighttext.setText(null);
this.widthtext.setText(null); }
} public static void main(String[] args) {
//new SetFrame();
}}
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;public class SouthPanel { /**
* @param args
*/ JLabel timeshow;
JLabel boundshow;
JTextField time;
JTextField bound;
JPanel jp; SouthPanel() { jp = new JPanel();
jp.setBackground(new Color(250, 250, 250));
timeshow = new JLabel();
boundshow = new JLabel();
time = new JTextField();
bound = new JTextField(); time.setEditable(false);
bound.setEditable(false); FlowLayout fl = new FlowLayout(FlowLayout.LEADING);
fl.setHgap(30);
fl.setVgap(10); jp.setSize(new Dimension(100, 10));
jp.setLayout(fl); timeshow.setText("Time:");
timeshow.setOpaque(false);
boundshow.setIcon(new ImageIcon("image\\1.gif")); jp.add(timeshow);
jp.add(time);
jp.add(boundshow);
jp.add(bound);
} public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame jf = new JFrame();
jf.add((new SouthPanel()).jp);
jf.setVisible(true);
} public JTextField getTime() {
return time;
} public void setTime(JTextField time) {
this.time = time;
} public JTextField getBound() {
return bound;
} public void setBound(JTextField bound) {
this.bound = bound;
}}
我是菜鸟,求指教