📄 frame1.java
字号:
package magic;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
JPanel contentPane;
int i=0;
double td;
String a;
String st;
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel[] b2=new JLabel[100];
JTextArea jTextArea1 = new JTextArea();
JPanel jPanel3 = new JPanel();
BorderLayout borderLayout3 = new BorderLayout();
JLabel jLabel4 = new JLabel();
JPanel jPanel4 = new JPanel();
JButton jButton1 = new JButton();
JTextArea jTextArea2 = new JTextArea();
JPanel jPanel5 = new JPanel();
GridLayout gridLayout2 = new GridLayout();
BorderLayout borderLayout4 = new BorderLayout();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setJMenuBar(jMenuBar1);
this.setResizable(false);
this.setSize(new Dimension(862, 430));
this.setTitle("魔幻图腾");
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setLayout(borderLayout2);
jPanel1.setLayout(borderLayout4);
jLabel1.setBackground(SystemColor.inactiveCaptionText);
jLabel1.setFont(new java.awt.Font("Dialog", 0, 53));
jLabel1.setOpaque(true);
jLabel1.setText(" ");
jLabel2.setBackground(SystemColor.inactiveCaptionText);
jLabel2.setOpaque(true);
jLabel2.setText(" ");
jLabel3.setBackground(SystemColor.inactiveCaptionText);
jLabel3.setOpaque(true);
jLabel3.setText(" ");
jLabel5.setBackground(new Color(200, 200, 200));
jLabel5.setBorder(BorderFactory.createRaisedBevelBorder());
jLabel5.setOpaque(true);
jLabel5.setHorizontalAlignment(SwingConstants.CENTER);
jLabel5.setHorizontalTextPosition(SwingConstants.CENTER);
jLabel5.setText(" ");
jLabel5.addMouseListener(new Frame1_jLabel5_mouseAdapter(this));
jPanel1.setBackground(SystemColor.inactiveCaptionText);
jTextArea1.setBackground(SystemColor.inactiveCaptionText);
jTextArea1.setEnabled(false);
jTextArea1.setForeground(new Color(0, 0, 118));
jTextArea1.setDisabledTextColor(SystemColor.desktop);
jTextArea1.setEditable(false);
jTextArea1.setText("魔幻图腾玩法:"+'\n'+
"你先在心里默念一个两位数,用这个两位数"+'\n'+
"减去它的十位和个位的和,得到的数在右边"+'\n'+
"所代表的图腾符号,当你点击上边的矩形时"+'\n'+
",矩形会显示出你的那个图腾,例如你想的"+'\n'+
"是76,那么76-(7+6)=63,那么当你点击"+'\n'+
"矩形,63所代表的图腾会显示在矩形上面!"+'\n'+
" 作者:lanner Neutron工作2006");
jTextArea1.setLineWrap(true);
jPanel3.setLayout(borderLayout3);
jLabel4.setBackground(SystemColor.inactiveCaptionText);
jLabel4.setOpaque(true);
jLabel4.setText(" ");
jPanel4.setBackground(SystemColor.inactiveCaptionText);
jPanel4.setLayout(gridBagLayout1);
jButton1.setFont(new java.awt.Font("Forte", 0, 18));
jButton1.setForeground(Color.blue);
jButton1.setText("try again");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jTextArea2.setBackground(SystemColor.inactiveCaptionText);
jTextArea2.setEnabled(false);
jTextArea2.setFont(new java.awt.Font("新宋体", 1, 25));
jTextArea2.setDisabledTextColor(SystemColor.desktop);
jTextArea2.setEditable(false);
jTextArea2.setLineWrap(true);
jTextArea2.setText("Can't believe it !"+'\n'+
"Click the botton "+'\n'+
"and try again !"+'\n'+
"如果您对本游戏感兴趣或有意见"+'\n'+
"联系我 QQ:214392346 ");
jPanel5.setLayout(gridLayout2);
gridLayout2.setColumns(10);
gridLayout2.setHgap(2);
gridLayout2.setRows(10);
gridLayout2.setVgap(2);
jPanel5.setBackground(SystemColor.inactiveCaptionText);
jMenu1.setBackground(SystemColor.inactiveCaptionText);
jMenu1.setText("菜单");
jMenuItem1.setText("退出");
jMenuItem1.addActionListener(new Frame1_jMenuItem1_actionAdapter(this));
jMenuItem2.setText("关于本游戏");
jMenuItem2.addActionListener(new Frame1_jMenuItem2_actionAdapter(this));
jMenuBar1.setBackground(SystemColor.inactiveCaptionText);
jPanel2.add(jLabel1, BorderLayout.NORTH);
jPanel2.add(jLabel2, BorderLayout.WEST);
jPanel2.add(jLabel3, BorderLayout.EAST);
jPanel2.add(jLabel5, BorderLayout.CENTER);
jPanel2.add(jTextArea1, BorderLayout.SOUTH);
jPanel4.add(jTextArea2, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(35, 93, 0, 0), 0, 0));
jPanel4.add(jButton1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(89, 265, 54, 126), 75, 23));
jPanel4.setVisible(false);
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jPanel5, BorderLayout.CENTER);
jPanel1.add(jPanel4, BorderLayout.NORTH);
jPanel3.add(jLabel4, BorderLayout.EAST);
contentPane.add(jPanel3, BorderLayout.WEST);
jPanel3.add(jPanel2, BorderLayout.CENTER);
jMenuBar1.add(jMenu1);
jMenu1.add(jMenuItem1);
jMenu1.addSeparator();
jMenu1.add(jMenuItem2);
for(i=0;i<=100;i++){
try{
b2[i] = new JLabel(String.valueOf(i));
b2[i].setBorder(BorderFactory.createEtchedBorder());
b2[i].setBackground(new Color(200, 200, 200));
b2[i].setOpaque(true);
jPanel5.add(b2[i], null);}
catch(Exception r){}
}
//
for(i=0;i<=19;i++){
b2[i].setForeground(Color.RED);
}
//
for(i=20;i<=39;i++){
b2[i].setForeground(Color.BLUE);
}
//
for(i=40;i<=59;i++){
b2[i].setForeground(new Color(255, 21, 152));
}
//
for(i=80;i<=99;i++){
b2[i].setForeground(new Color(208, 55, 255));
}
this.restar();
this.changeic();
}
public void restar(){
for(i=0;i<=99;i++){
try{
double t=Math.random()*20;
a=String.valueOf((int)t);
st=a+".jpg";
Icon ic=new ImageIcon("all\\"+st);
b2[i].setIcon(ic);}
catch(Exception r){}
}
}
public void changeic(){
td=Math.random()*20;
a=String.valueOf((int)td);
st=a+".jpg";
Icon ic=new ImageIcon("all\\"+st);
for(i=1;i<=11;i++){
b2[i*9].setIcon(ic);
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jLabel5_mouseClicked(MouseEvent e) {
Icon i3=new ImageIcon("ans\\"+(int)td+".jpg");
jLabel5.setIcon(i3);
jPanel5.setVisible(false);
jPanel4.setVisible(true);
}
void jButton1_actionPerformed(ActionEvent e) {
jPanel5.setVisible(true);
jPanel4.setVisible(false);
this.restar();
this.changeic();
jLabel5.setIcon(null);
}
void jMenuItem1_actionPerformed(ActionEvent e) {
System.exit(0);
}
void jMenuItem2_actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this,"本游戏由Neutron工作室研制!作者:lanner 06.04.18"
,"★关于魔幻图腾!★",JOptionPane.INFORMATION_MESSAGE);
}
}
class Frame1_jLabel5_mouseAdapter extends java.awt.event.MouseAdapter {
Frame1 adaptee;
Frame1_jLabel5_mouseAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jLabel5_mouseClicked(e);
}
}
class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Frame1_jMenuItem1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jMenuItem1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem1_actionPerformed(e);
}
}
class Frame1_jMenuItem2_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jMenuItem2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem2_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -