summer820228 2015-07-21 13:58 采纳率: 33.3%
浏览 1964

tf.setBounds(80, 200,200,200); 竖座标超过80 程序不运行

import java.awt.*;
import java.awt.event.*;
import java.util.Random;

import javax.swing.*;

public class Three extends JFrame implements ActionListener, Runnable {

/**
 * 
 */
private static final long serialVersionUID = -8560277451929244119L;
JTextField tf = new JTextField();
JButton b1 = new JButton("开始");
JButton b2 = new JButton("停止");
JButton b3 = new JButton("END");
boolean isGo = false;
String path = "three.jpg";
ImageIcon background = new ImageIcon(path);
JTextArea jiang1= new JTextArea();
int choujiangcishu=1;

public Three() {
    this.getContentPane().setLayout(null);
    Dimension srcDim = Toolkit.getDefaultToolkit().getScreenSize();  

    this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    this.getContentPane().add(tf);


    ImageIcon background = new ImageIcon(path);// 背景图片
    JLabel jlbg = new JLabel(background);// 把背景图片显示在一个标签里面
    jlbg.setBounds(0, 0, srcDim.width, srcDim.height);// 把标签的大小位置设置为图片刚好填充整个面板
    JPanel imagePanel = (JPanel) this.getContentPane();
    imagePanel.setOpaque(false);//设置透明
    this.getLayeredPane().add(jlbg, new Integer(Integer.MIN_VALUE));

    /*tf.setFont(new Font("Courier", Font.PLAIN, 35));
    tf.setHorizontalAlignment(JLabel.LEFT);
    tf.setOpaque(false);
    tf.setBackground(Color.red);// 按钮红色背景
    tf.setEditable(false);//不可编辑
    //tf.setBorder(BorderFactory.createEmptyBorder());//无边框
    tf.setBounds(80, 80, srcDim.width/6, srcDim.height/22);
    */
    tf.setFont(new Font("Courier", Font.PLAIN, 35));
    tf.setHorizontalAlignment(JLabel.LEFT);
    tf.setOpaque(false);
    tf.setBackground(Color.red);// 按钮红色背景
    tf.setEditable(false);//不可编辑
    //tf.setBorder(BorderFactory.createEmptyBorder());//无边框
*************** tf.setBounds(80, 200,200,200);



    b1.setBounds(1,100,10,10);
    b2.setBounds(1,200,10,10);
    b3.setBounds(1,300,10,10);




    this.getContentPane().add(tf);
    this.getContentPane().add(b1);
    this.getContentPane().add(b2);
    this.getContentPane().add(b3);



    b1.setActionCommand("start");
    b2.setActionCommand("end");
    b3.setActionCommand("over");

    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);

    SymListener sy = new SymListener();
    b1.registerKeyboardAction(sy,KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); 
    b2.registerKeyboardAction(sy,KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); 
    b3.registerKeyboardAction(sy,KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); 
    //jButton.setMnemonic(KeyEvent.VK_ENTER);
    b2.setEnabled(false);

    super.setUndecorated(true);// 无标题栏
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    this.setLocation(0, 0);
    Cursor cu = new Cursor(Cursor.HAND_CURSOR);
    this.setCursor(cu);
    this.setVisible(true);
    tf.setText("888888");
    operdata geshu=new operdata();
    go(geshu.getCount());

}    

public void go(int p) {
    while (true) {
        if (isGo == true) {
            String s = "";

            for (int j = 1; j <= 1; j++) {
                int i = (int) (Math.random()*p+1);//设定奖项总数
                if (i < 10) {
                    s = s + "00000" + i;
                } else if(i<100 & i>=10) 
                {
                    s = s + "0000" + i;
                }else if(i<1000 & i>=100) 
                {
                    s = s + "000" + i;
                }else if(i<10000 & i>=1000) 
                {
                    s = s + "00" + i;
                }else if(i<100000 & i>=10000) 
                {
                    s = s + "0" + i;
                }else
                {
                    s = s +  i;
                }

            }
            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);
    } 
    if (s.equals("end")){
        isGo = false;
        operdata aaa =new operdata();
        String bb= aaa.getuserdata(tf.getText());
        jiang1.setText(jiang1.getText()+"\n"+""+(choujiangcishu++)+":  "+tf.getText()+bb);

        b2.setEnabled(false);
        b1.setEnabled(true);
    }*/
}

public static void main(String[] args)  {
    //Dimension srcDim = Toolkit.getDefaultToolkit().getScreenSize(); 
   // ImgUtil image =new ImgUtil();
    //image.createThumb("3.png", "223.jpg",(int)srcDim.getWidth(), (int)srcDim.getHeight());
    new Three();

} 
class SymListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    Object obj = e.getSource();

    if (obj == b1) {
            isGo = true;
            b1.setEnabled(false);
            b2.setEnabled(true);
    } else if (obj == b2) {
        isGo=false;
        b2.setEnabled(false);
        b1.setEnabled(true);


    }else if (obj == b3) {
        dispose();

    }
    }
    }
@Override
public void run() {
    // TODO Auto-generated method stub

}

//@Override
/*public void run() {

    this.yunyingzhongxingo();
}*/

}

  • 写回答

5条回答 默认 最新

  • danielinbiti 2015-07-21 14:08
    关注

    代码拷贝进去运行试了一下,没报错。最好把你的错误贴出来

    评论

报告相同问题?

悬赏问题

  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿