📄 winframe.java
字号:
/**
* This program is written by Jerry Shen(Shen Ji Feng) use the technology of
* SWING GUI and the OO design
*
* @author Jerry Shen all rights reserved.
* Email:jerry.shen@cognizant.com; jerry_shen_sjf@yahoo.com.cn
* Please report bug to these emails.
* Open source under GPLv3
*
* version 2.0
*/
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
@SuppressWarnings("serial")
class WinFrame extends JFrame implements MouseListener {
private JPanel winPane;
private JLabel msg1;
private JLabel msg2;
private JLabel msg3;
private JButton easy;
private JButton middle;
private JButton hard;
private JButton customer;
private int level;
private boolean isOk = false;
private boolean isCustomer = false;
private CustomerFrame customerFrame;
public WinFrame(String strName, CustomerFrame customerFrame) {
super(strName);
this.customerFrame = customerFrame;
setSize(170, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
level = 1;
winPane = new JPanel();
msg1 = new JLabel(" Congratulation! ");
msg2 = new JLabel(" You win. ");
msg3 = new JLabel(" Click to restart! ");
easy = new JButton("Easy");
easy.addMouseListener(this);
middle = new JButton("Middle");
middle.addMouseListener(this);
hard = new JButton("Hard");
hard.addMouseListener(this);
customer = new JButton("Customer");
customer.addMouseListener(this);
winPane.add(msg1);
winPane.add(msg2);
winPane.add(msg3);
winPane.add(easy);
winPane.add(middle);
winPane.add(hard);
winPane.add(customer);
setContentPane(winPane);
setLocation(250, 220);
}
public int getMineNum() {
return (level*12);
}
public boolean getWinOk() {
return (isOk);
}
public void setWinOk(boolean flag){
isOk = flag;
}
public boolean isCustomer(){
return isCustomer;
}
public void setCustomer(boolean flag){
isCustomer = flag;
}
// the event handle to deal with the mouse click
public void mouseClicked(MouseEvent e) {
if (e.getSource() == easy) {
level = 1;
setCustomer(false);
setWinOk(true);
}
if (e.getSource() == middle) {
level = 2;
setCustomer(false);
setWinOk(true);
}
if (e.getSource() == hard) {
level = 3;
setCustomer(true);
setWinOk(true);
}
if (e.getSource()== customer){
this.setVisible(false);
customerFrame.setVisible(true);
Timer winTimer= new Timer();
winTimer.schedule(new TimerTask(){
public void run() {
customerFrame.setOk(false);
while(!customerFrame.isOk()){
}
setCustomer(true);
setWinOk(true);
}
},0L);
}
this.setVisible(false);
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public static void main(String[] args) {
WinFrame win = new WinFrame("Win",new CustomerFrame("Test"));
win.setVisible(true);
}
public CustomerFrame getCustomerFrame() {
return customerFrame;
}
public void setCustomerFrame(CustomerFrame customerFrame) {
this.customerFrame = customerFrame;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -