📄 goodlucky1.java
字号:
/*
* GoodLucky1.java
*
* Created on 2007年12月29日, 下午3:39
*/
package org.Adam;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.util.Random;
import javax.swing.JFrame;
/**
*
* @author Administrator
*/
public class GoodLucky1 extends javax.swing.JFrame {
boolean isGo = false;
/** Creates new form GoodLucky1 */
public GoodLucky1() {
initComponents();
b1.setActionCommand("start");
// b1.addActionListener(this);
// b2.addActionListener(this);
b2.setEnabled(false);
//this.getContentPane().add(tf,"North");
// this.getContentPane().add(p,"South");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// this.setSize(300,200);
// this.setLocation(300,300);
// Cursor cu = new Cursor(Cursor.HAND_CURSOR);
// this.setCursor(cu);
this.setVisible(true);
tf.setText("welcome you! ");
this.go();
}
public void go(){
while(true){
if(isGo == true){
String s = "";
Random aa=new Random();
int b=40506226+aa.nextInt(42);
s=String.valueOf(b);
tf.setText(s);
}
try{
Thread.sleep(10);
}catch(java.lang.InterruptedException e){
e.printStackTrace();
}
}
}
public void actionPerformed(ActionEvent e){
String s = e.getActionCommand();
if(s.equals("start")){
isGo = true;
b1.setEnabled(false);
b2.setEnabled(true);
}else{
isGo = false;
b2.setEnabled(false);
b1.setEnabled(true);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
p = new javax.swing.JPanel();
b1 = new javax.swing.JButton();
b2 = new javax.swing.JButton();
tf = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
b1.setText("\u5f00\u59cb");
b1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b1ActionPerformed(evt);
}
});
b2.setText("\u505c\u6b62");
org.jdesktop.layout.GroupLayout pLayout = new org.jdesktop.layout.GroupLayout(p);
p.setLayout(pLayout);
pLayout.setHorizontalGroup(
pLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(pLayout.createSequentialGroup()
.add(82, 82, 82)
.add(b1)
.add(85, 85, 85)
.add(b2)
.addContainerGap(119, Short.MAX_VALUE))
);
pLayout.setVerticalGroup(
pLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, pLayout.createSequentialGroup()
.addContainerGap(194, Short.MAX_VALUE)
.add(pLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(b1)
.add(b2))
.add(63, 63, 63))
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(p, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(119, 119, 119)
.add(tf, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 162, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(119, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(37, 37, 37)
.add(tf, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 38, Short.MAX_VALUE)
.add(p, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void b1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b1ActionPerformed
// TODO 将在此处添加您的处理代码:
// this.actionPerformed(java.awt.event.ActionEvent evt);
}//GEN-LAST:event_b1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new GoodLucky1();
}
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton b1;
private javax.swing.JButton b2;
private javax.swing.JPanel p;
private javax.swing.JTextField tf;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -