这段代码我有很多的地方看不懂,希望大家不吝赐教问题1:其中蓝色的代码我看不懂.问题2:为什么有的代码上有一道横线,有横线表示什么意思?问题3:这段代码没有写全,而且投注功能没有实现,应该如何修改才能实现!import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.List;
import java.awt.event.*;
class MyFrame extends JFrame {
public MyFrame() {
super("赛马大会");
GraphicPanel gp = new GraphicPanel();
OperatorPanel op = new OperatorPanel();
MyThread3 mt1 = new MyThread3();
mt1.setGp(gp);
MyThread2 mt2 = new MyThread2();
mt2.setGp(gp);
MyThread4 mt3 = new MyThread4();
mt3.setGp(gp);
MyThread mt = new MyThread();
mt.setGp(gp);
Thread[] thread = {mt,mt1,mt2,mt3};
this.setLayout(new GridLayout(2,1));
op.setThread1(thread);
add(gp);
add(op);
this.setSize(800,600);
this.setLocation(100,100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class GraphicPanel extends JPanel {
int x = 0;
int y = 0;
int x1 = 0;
int y1 = 70;
int x2 = 0;
int y2 = 140;
int x3 = 0;
int y3 = 210;
public GraphicPanel() {
this.setBackground(Color.white);
}
public void fn() {
this.repaint();
}
public void paint(Graphics g) {
super.paint(g);
Image i = Toolkit.getDefaultToolkit().getImage("img\\001.gif");
g.drawString("1",20,35);
g.drawImage(i,x,y,null,this);
g.drawString("2",20,105);
g.drawImage(i,x1,y1,null,this);
g.drawString("3",20,175);
g.drawImage(i,x2,y2,null,this);
g.drawString("4",20,245);
g.drawImage(i,x3,y3,null,this);
g.setColor(Color.red);
g.fillRect(770,0,3,330);
}
}
class MyThread2 extends Thread {
GraphicPanel gp;
public void setGp(GraphicPanel gp) {
this.gp = gp;
}
public void run() {
try {
while(true) {
if(gp.x == 650) {
OperatorPanel.setString("1");
}
gp.fn();
gp.x += 10;
Random r = new Random(new Date().getTime());
Thread.sleep(r.nextInt(saima.num));
if(gp.x >= 800) {
gp.x = 0;
this.suspend();
}
}
} catch(Exception e) {}
}
}
class MyThread extends Thread {
GraphicPanel gp;
public void setGp(GraphicPanel gp) {
this.gp = gp;
}
public void run() {
try {
while(true) {
if(gp.x1 == 650) {
OperatorPanel.setString("2");
}
gp.fn();
gp.x1 += 10;
Random r = new Random(new Date().getTime());
Thread.sleep(r.nextInt(saima.num));
if(gp.x1 >= 800) {
gp.x1 = 0;
this.suspend();
}
}
} catch(Exception e) {}
}
}
class MyThread3 extends Thread {
GraphicPanel gp;
public void setGp(GraphicPanel gp) {
this.gp = gp;
}
public void run() {
try {
while(true) {
if(gp.x2 == 650) {
OperatorPanel.setString("3");
}
gp.fn();
gp.x2 += 10;
Random r = new Random(new Date().getTime());
Thread.sleep(r.nextInt(saima.num));
if(gp.x2 >= 800) {
gp.x2 = 0;
this.suspend();
}
}
} catch(Exception e) {}
}
}
class MyThread4 extends Thread {
GraphicPanel gp;
public void setGp(GraphicPanel gp) {
this.gp = gp;
}
public void run() {
try {
while(true) {
if(gp.x3 == 650) {
OperatorPanel.setString("4");
}
gp.fn();
gp.x3 += 10;
Random r = new Random(new Date().getTime());
Thread.sleep(r.nextInt(saima.num));
if(gp.x3 >= 800) {
gp.x3 = 0;
this.suspend();
}
}
} catch(Exception e) {}
}
}
class OperatorPanel extends JPanel implements ActionListener {
static JButton jb = new JButton("开始");
JRadioButton jrb1 = new JRadioButton("1号马");
JRadioButton jrb2 = new JRadioButton("2号马");
JRadioButton jrb3 = new JRadioButton("3号马");
JRadioButton jrb4 = new JRadioButton("4号马");
ButtonGroup bg = new ButtonGroup();
JLabel jl = new JLabel("请选择一个");
JLabel jlError = new JLabel();
static JLabel jlMoney = new JLabel("您的资金为:");
static List list = new List();
static JTextField jtf = new JTextField("0");
JPanel jp1 = new JPanel();
Thread[] thread;
static int flag = 0;
static int iflag = 0;
static String select;
static int no = 1;
static int iMoney = 10000;
static int money = 0;
public OperatorPanel() {
this.setLayout(new BorderLayout());
jp1.setLayout(new GridLayout(4,3));
jrb1.setSelected(true);
jlMoney.setText(jlMoney.getText() + iMoney);
jlError.setForeground(Color.red);
jb.setBackground(Color.orange);
bg.add(jrb1);
bg.add(jrb2);
bg.add(jrb3);
bg.add(jrb4);
jp1.add(jl); jp1.add(jrb1); jp1.add(jlMoney); 
jp1.add(new JLabel("")); jp1.add(jrb2); jp1.add(jtf);
jp1.add(new JLabel("")); jp1.add(jrb3); jp1.add(jlError);
jp1.add(new JLabel("")); jp1.add(jrb4); jp1.add(jb);
jb.addActionListener(this);
this.add(jp1,BorderLayout.NORTH);
this.add(list,BorderLayout.CENTER);
}
public void setThread1(Thread[] mt) {
this.thread = mt;
}
public void actionPerformed(ActionEvent e) {
iflag = 0;
try {
money = Integer.parseInt(jtf.getText());
if(money > iMoney || iMoney <= 0) {
iflag = 1;
}
if(money <= 0) {
iflag = 3;
}
} catch(Exception ex) {
iflag = 2;
}
if(iflag == 0) {
jlError.setText("");
Random r = new Random();
list.clear();
no =1;
int num1,num2,num3,num4;
num1 = r.nextInt(4);
if(jrb1.isSelected()) {
select = "1号马";
}
else if(jrb2.isSelected()) {
select = "2号马";
}
else if(jrb3.isSelected()) {
select = "3号马";
}
else if(jrb4.isSelected()) {
select = "4号马";
}
while(true) {
num2 = r.nextInt(4);
if(num2 == num1) {
continue;
}
else {
break;
}
}
while(true) {
num3 = r.nextInt(4);
if(num3 == num1 || num3 == num2) {
continue;
}
else {
break;
}
}
while(true) {
num4 = r.nextInt(4);
if(num4 == num1 || num4 == num2 || num4 ==num3) {
continue;
}
else {
break;
}
}
if(flag == 0) {
thread[num1].start();
thread[num2].start();
thread[num3].start();
thread[num4].start();
flag = 1;
jb.setLabel("继续");
jb.setEnabled(false);
}
else if(flag == 1) {
thread[num1].resume();
thread[num2].resume();
thread[num3].resume();
thread[num4].resume();
jb.setLabel("继续");
jb.setEnabled(false);
}
else if(iflag == 1) {
jlError.setText("您的资金不足");
}
else if(iflag == 2) {
jlError.setText("输入格式不正确");
}
else if(iflag == 3) {
jlError.setText("请正确输入金额");
}
}
}
public static void setString(String str) {
list.add("第" + no + "名是:" + str + "号马");
no++;
if(list.getItemCount() == 4) {
String strs[] = list.getItem(0).split(":");
if(strs[1].equals(select)) {
list.add("恭喜您猜对了");
iMoney += money;
jlMoney.setText("您的资金为:" + iMoney);
}
else {
list.add("您猜错了,下次再来");
iMoney -= money;
jlMoney.setText("您的资金为:" + iMoney);
}
}
if(list.getItemCount() == 5) {
jtf.requestFocus();
jtf.selectAll();
jb.setEnabled(true);
}
}
}
public class saima {
static final int num = 500;
public static void main(String[] args) {
new MyFrame();
}
}

解决方案 »

  1.   

    有横线的是jdk中已经过时的方法
    蓝色的代码太长了,不知道你具体哪看不懂,别说都看不懂
      

  2.   

    public   void   actionPerformed(ActionEvent   e)   {
    iflag   =   0;
    try   {
    money   =   Integer.parseInt(jtf.getText());
    if(money   >   iMoney   ¦ ¦   iMoney   <=   0)   {
    iflag   =   1;
    }
    if(money   <=   0)   {
    iflag   =   3;
    }
    }   catch(Exception   ex)   {
    iflag   =   2;
    }
    if(iflag   ==   0)   {
    jlError.setText("");
    Random   r   =   new   Random();
    list.clear();
    no   =1;
    int   num1,num2,num3,num4;
    num1   =   r.nextInt(4);
    if(jrb1.isSelected())   {
    select   =   "1号马";
    }
    else   if(jrb2.isSelected())   {
    select   =   "2号马";
    }
    else   if(jrb3.isSelected())   {
    select   =   "3号马";
    }
    else   if(jrb4.isSelected())   {
    select   =   "4号马";
    }
    while(true)   {
    num2   =   r.nextInt(4);
    if(num2   ==   num1)   {
    continue;
    }
    else   {
    break;
    }
    }
    while(true)   {
    num3   =   r.nextInt(4);
    if(num3   ==   num1   ¦ ¦   num3   ==   num2)   {
    continue;
    }
    else   {
    break;
    }
    }
    while(true)   {
    num4   =   r.nextInt(4);
    if(num4   ==   num1   ¦ ¦   num4   ==   num2   ¦ ¦   num4   ==num3)   {
    continue;
    }
    else   {
    break;
    }
    }
    if(flag   ==   0)   {
    thread[num1].start();
    thread[num2].start();
    thread[num3].start();
    thread[num4].start();
    flag   =   1;
    jb.setLabel("继续");
    jb.setEnabled(false);
    }
    else   if(flag   ==   1)   {
    thread[num1].resume();
    thread[num2].resume();
    thread[num3].resume();
    thread[num4].resume();
    jb.setLabel("继续");
    jb.setEnabled(false);
    }
    else   if(iflag   ==   1)   {
    jlError.setText("您的资金不足");            //这段代码没有实现,不知道为什么?
    }
    else   if(iflag   ==   2)   {
    jlError.setText("输入格式不正确");
    }
    else   if(iflag   ==   3)   {
    jlError.setText("请正确输入金额");
    }
    }
    }
    public   static   void   setString(String   str)   {
    list.add("第"   +   no   +   "名是:"   +   str   +   "号马");
    no++;
    if(list.getItemCount()   ==   4)   {
    String   strs[]   =   list.getItem(0).split(":");
    if(strs[1].equals(select))   {
    list.add("恭喜您猜对了");
    iMoney   +=   money;
    jlMoney.setText("您的资金为:"   +   iMoney);
    }
    else   {
    list.add("您猜错了,下次再来");
    iMoney   -=   money;
    jlMoney.setText("您的资金为:"   +   iMoney);
    }
    }
    if(list.getItemCount()   ==   5)   {
    jtf.requestFocus();
    jtf.selectAll();
    jb.setEnabled(true);
    }
    }
    }
      

  3.   

    这回看起来应该不会太累了吧?import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.List;
    import java.awt.event.*;
    class MyFrame extends JFrame {
    public MyFrame() {
    super("赛马大会");
    GraphicPanel gp = new GraphicPanel();
    OperatorPanel op = new OperatorPanel();
    MyThread3 mt1 = new MyThread3();
    mt1.setGp(gp);
    MyThread2 mt2 = new MyThread2();
    mt2.setGp(gp);
    MyThread4 mt3 = new MyThread4();
    mt3.setGp(gp);
    MyThread mt = new MyThread();
    mt.setGp(gp);
    Thread[] thread = {mt,mt1,mt2,mt3};
    this.setLayout(new GridLayout(2,1));
    op.setThread1(thread);
    add(gp);
    add(op);
    this.setSize(800,600);
    this.setLocation(100,100);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }
    class GraphicPanel extends JPanel {
    int x = 0;
    int y = 0;
    int x1 = 0;
    int y1 = 70;
    int x2 = 0;
    int y2 = 140;
    int x3 = 0;
    int y3 = 210;
    public GraphicPanel() {
    this.setBackground(Color.white);
    }
    public void fn() {
    this.repaint();
    }
    public void paint(Graphics g) {
    super.paint(g);
    Image i = Toolkit.getDefaultToolkit().getImage("img\\001.gif");
    g.drawString("1",20,35);
    g.drawImage(i,x,y,null,this);
    g.drawString("2",20,105);
    g.drawImage(i,x1,y1,null,this);
    g.drawString("3",20,175);
    g.drawImage(i,x2,y2,null,this);
    g.drawString("4",20,245);
    g.drawImage(i,x3,y3,null,this);
    g.setColor(Color.red);
    g.fillRect(770,0,3,330);
    }
    }
    class MyThread2 extends Thread {
    GraphicPanel gp;
    public void setGp(GraphicPanel gp) {
    this.gp = gp;
    }
    public void run() {
    try {
    while(true) {
    if(gp.x == 650) {
    OperatorPanel.setString("1");
    }
    gp.fn();
    gp.x += 10;
    Random r = new Random(new Date().getTime());
    Thread.sleep(r.nextInt(saima.num));
    if(gp.x >= 800) {
    gp.x = 0;
    this.suspend();
    }
    }
    } catch(Exception e) {}
    }
    }
    class MyThread extends Thread {
    GraphicPanel gp;
    public void setGp(GraphicPanel gp) {
    this.gp = gp;
    }
    public void run() {
    try {
    while(true) {
    if(gp.x1 == 650) {
    OperatorPanel.setString("2");
    }
    gp.fn();
    gp.x1 += 10;
    Random r = new Random(new Date().getTime());
    Thread.sleep(r.nextInt(saima.num));
    if(gp.x1 >= 800) {
    gp.x1 = 0;
    this.suspend();
    }
    }
    } catch(Exception e) {}
    }
    }
    class MyThread3 extends Thread {
    GraphicPanel gp;
    public void setGp(GraphicPanel gp) {
    this.gp = gp;
    }
    public void run() {
    try {
    while(true) {
    if(gp.x2 == 650) {
    OperatorPanel.setString("3");
    }
    gp.fn();
    gp.x2 += 10;
    Random r = new Random(new Date().getTime());
    Thread.sleep(r.nextInt(saima.num));
    if(gp.x2 >= 800) {
    gp.x2 = 0;
    this.suspend();
    }
    }
    } catch(Exception e) {}
    }
    }
    class MyThread4 extends Thread {
    GraphicPanel gp;
    public void setGp(GraphicPanel gp) {
    this.gp = gp;
    }
    public void run() {
    try {
    while(true) {
    if(gp.x3 == 650) {
    OperatorPanel.setString("4");
    }
    gp.fn();
    gp.x3 += 10;
    Random r = new Random(new Date().getTime());
    Thread.sleep(r.nextInt(saima.num));
    if(gp.x3 >= 800) {
    gp.x3 = 0;
    this.suspend();
    }
    }
    } catch(Exception e) {}
    }
    }
    class OperatorPanel extends JPanel implements ActionListener {
    static JButton jb = new JButton("开始");
    JRadioButton jrb1 = new JRadioButton("1号马");
    JRadioButton jrb2 = new JRadioButton("2号马");
    JRadioButton jrb3 = new JRadioButton("3号马");
    JRadioButton jrb4 = new JRadioButton("4号马");
    ButtonGroup bg = new ButtonGroup();
    JLabel jl = new JLabel("请选择一个");
    JLabel jlError = new JLabel();
    static JLabel jlMoney = new JLabel("您的资金为:");
    static List list = new List();
    static JTextField jtf = new JTextField("0");
    JPanel jp1 = new JPanel();
    Thread[] thread;
    static int flag = 0;
    static int iflag = 0;
    static String select;
    static int no = 1;
    static int iMoney = 10000;
    static int money = 0;
    public OperatorPanel() {
    this.setLayout(new BorderLayout());
    jp1.setLayout(new GridLayout(4,3));
    jrb1.setSelected(true);
    jlMoney.setText(jlMoney.getText() + iMoney);
    jlError.setForeground(Color.red);
    jb.setBackground(Color.orange);
    bg.add(jrb1);
    bg.add(jrb2);
    bg.add(jrb3);
    bg.add(jrb4);
    jp1.add(jl); jp1.add(jrb1); jp1.add(jlMoney); 
    jp1.add(new JLabel("")); jp1.add(jrb2); jp1.add(jtf);
    jp1.add(new JLabel("")); jp1.add(jrb3); jp1.add(jlError);
    jp1.add(new JLabel("")); jp1.add(jrb4); jp1.add(jb);
    jb.addActionListener(this);
    this.add(jp1,BorderLayout.NORTH);
    this.add(list,BorderLayout.CENTER);
    }
    public void setThread1(Thread[] mt) {
    this.thread = mt;
    }
    public void actionPerformed(ActionEvent e) {
    iflag = 0;
    try {
    money = Integer.parseInt(jtf.getText());
    if(money > iMoney || iMoney <= 0) {
    iflag = 1;
    }
    if(money <= 0) {
    iflag = 3;
    }
    } catch(Exception ex) {
    iflag = 2;
    }
    if(iflag == 0) {
    jlError.setText("");
    Random r = new Random();
    list.clear();
    no = 1;
    int num1,num2,num3,num4;
    num1 = r.nextInt(4);
    if(jrb1.isSelected()) {
    select = "1号马";
    }
    else if(jrb2.isSelected()) {
    select = "2号马";
    }
    else if(jrb3.isSelected()) {
    select = "3号马";
    }
    else if(jrb4.isSelected()) {
    select = "4号马";
    }
    while(true) {
    num2 = r.nextInt(4);
    if(num2 == num1) {
    continue;
    }
    else {
    break;
    }
    }
    while(true) {
    num3 = r.nextInt(4);
    if(num3 == num1 || num3 == num2) {
    continue;
    }
    else {
    break;
    }
    }
    while(true) {
    num4 = r.nextInt(4);
    if(num4 == num1 || num4 == num2 || num4 ==num3) {
    continue;
    }
    else {
    break;
    }
    }
    if(flag == 0) {
    thread[num1].start();
    thread[num2].start();
    thread[num3].start();
    thread[num4].start();
    flag = 1;
    jb.setLabel("继续");
    jb.setEnabled(false);
    }
    else if(flag == 1) {
    thread[num1].resume();
    thread[num2].resume();
    thread[num3].resume();
    thread[num4].resume();
    jb.setLabel("继续");
    jb.setEnabled(false);
    }
    else if(iflag == 1) {
    jlError.setText("您的资金不足");
    }
    else if(iflag == 2) {
    jlError.setText("输入格式不正确");
    }
    else if(iflag == 3) {
    jlError.setText("请正确输入金额");
    }
    }
    }
    public static void setString(String str) {
    list.add("第" + no + "名是:" + str + "号马");
    no++;
    if(list.getItemCount() == 4) {
    String strs[] = list.getItem(0).split(":");
    if(strs[1].equals(select)) {
    list.add("恭喜您猜对了");
    iMoney += money;
    jlMoney.setText("您的资金为:" + iMoney);
    }
    else {
    list.add("您猜错了,下次再来");
    iMoney -= money;
    jlMoney.setText("您的资金为:" + iMoney);
    }
    }
    if(list.getItemCount() == 5) {
    jtf.requestFocus();
    jtf.selectAll();
    jb.setEnabled(true);
    }
    }
    }
    public class saima {
    static final int num = 500;
    public static void main(String[] args) {
    new MyFrame();
    }
    }
      

  4.   

    class OperatorPanel extends JPanel implements ActionListener {
        static JButton jb = new JButton("开始");
        JRadioButton jrb1 = new JRadioButton("1号马");
        JRadioButton jrb2 = new JRadioButton("2号马");
        JRadioButton jrb3 = new JRadioButton("3号马");
        JRadioButton jrb4 = new JRadioButton("4号马");
        ButtonGroup bg = new ButtonGroup();
        JLabel jl = new JLabel("请选择一个");
        JLabel jlError = new JLabel();
        static JLabel jlMoney = new JLabel("您的资金为:");
        static List list = new List();
        static JTextField jtf = new JTextField("0");
        JPanel jp1 = new JPanel();
        Thread[] thread;
        static int flag = 0;
        static int iflag = 0;
        static String select;
        static int no = 1;
        static int iMoney = 10000;
        static int money = 0;
        public OperatorPanel() {
            this.setLayout(new BorderLayout());
            jp1.setLayout(new GridLayout(4,3));
            jrb1.setSelected(true);
            jlMoney.setText(jlMoney.getText() + iMoney);
            jlError.setForeground(Color.red);
            jb.setBackground(Color.orange);
            bg.add(jrb1);
            bg.add(jrb2);
            bg.add(jrb3);
            bg.add(jrb4);
            jp1.add(jl); jp1.add(jrb1); jp1.add(jlMoney); 
            jp1.add(new JLabel("")); jp1.add(jrb2); jp1.add(jtf);
            jp1.add(new JLabel("")); jp1.add(jrb3); jp1.add(jlError);
            jp1.add(new JLabel("")); jp1.add(jrb4); jp1.add(jb);
            jb.addActionListener(this);
            this.add(jp1,BorderLayout.NORTH);
            this.add(list,BorderLayout.CENTER);        
        }
        public void setThread1(Thread[] mt) {
            this.thread = mt;
        }
        public void actionPerformed(ActionEvent e) {
            iflag = 0;
            try {
                money = Integer.parseInt(jtf.getText());
                if(money > iMoney || iMoney <= 0) {
                    iflag = 1;
                }
                if(money <= 0) {
                    iflag = 3;
                }                                    [color=#FF0000] //这段代码麻烦指导一下,如何才能够实现资金投注功能
            } catch(Exception ex) {           
                iflag = 2;
            }
            if(iflag == 0) {
                jlError.setText("");
                Random r = new Random();
                list.clear();
                no = 1;
                int num1,num2,num3,num4;
                num1 = r.nextInt(4);
                if(jrb1.isSelected()) {
                    select = "1号马";
                }
                else if(jrb2.isSelected()) {
                    select = "2号马";
                }
                else if(jrb3.isSelected()) {
                    select = "3号马";
                }
                else if(jrb4.isSelected()) {
                    select = "4号马";
                }
                while(true) {
                    num2 = r.nextInt(4);
                    if(num2 == num1) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
                while(true) {
                    num3 = r.nextInt(4);
                    if(num3 == num1 || num3 == num2) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
                while(true) {
                    num4 = r.nextInt(4);
                    if(num4 == num1 || num4 == num2 || num4 ==num3) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
                if(flag == 0) {
                    thread[num1].start();
                    thread[num2].start();
                    thread[num3].start();
                    thread[num4].start();
                    flag = 1;
                    jb.setLabel("继续");
                    jb.setEnabled(false);
                }
                else if(flag == 1) {
                    thread[num1].resume();
                    thread[num2].resume();
                    thread[num3].resume();
                    thread[num4].resume();
                    jb.setLabel("继续");
                    jb.setEnabled(false);
                }
                else if(iflag == 1) {
                    jlError.setText("您的资金不足");
                }
                else if(iflag == 2) {
                    jlError.setText("输入格式不正确");
                }
                else if(iflag == 3) {
                    jlError.setText("请正确输入金额");
                }
            }        
        }
        [/color]public static void setString(String str) {
            list.add("第" + no + "名是:" + str + "号马");
            no++;
            if(list.getItemCount() == 4) {
                String strs[] = list.getItem(0).split(":");
                if(strs[1].equals(select)) {
                    list.add("恭喜您猜对了");
                    iMoney += money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
                else {
                    list.add("您猜错了,下次再来");
                    iMoney -= money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
            }
            if(list.getItemCount() == 5) {
                jtf.requestFocus();
                jtf.selectAll();
                jb.setEnabled(true);
            }
        }
    }
      

  5.   

    请教这段代码为什么很多功能没有实现?class OperatorPanel extends JPanel implements ActionListener {
        static JButton jb = new JButton("开始");
        JRadioButton jrb1 = new JRadioButton("1号马");
        JRadioButton jrb2 = new JRadioButton("2号马");
        JRadioButton jrb3 = new JRadioButton("3号马");
        JRadioButton jrb4 = new JRadioButton("4号马");
        ButtonGroup bg = new ButtonGroup();
        JLabel jl = new JLabel("请选择一个");
        JLabel jlError = new JLabel();
        static JLabel jlMoney = new JLabel("您的资金为:");
        static List list = new List();
        static JTextField jtf = new JTextField("0");
        JPanel jp1 = new JPanel();
        Thread[] thread;
        static int flag = 0;
        static int iflag = 0;
        static String select;
        static int no = 1;
        static int iMoney = 10000;
        static int money = 0;
        public OperatorPanel() {
            this.setLayout(new BorderLayout());
            jp1.setLayout(new GridLayout(4,3));
            jrb1.setSelected(true);
            jlMoney.setText(jlMoney.getText() + iMoney);
            jlError.setForeground(Color.red);
            jb.setBackground(Color.orange);
            bg.add(jrb1);
            bg.add(jrb2);
            bg.add(jrb3);
            bg.add(jrb4);
            jp1.add(jl); jp1.add(jrb1); jp1.add(jlMoney); 
            jp1.add(new JLabel("")); jp1.add(jrb2); jp1.add(jtf);
            jp1.add(new JLabel("")); jp1.add(jrb3); jp1.add(jlError);
            jp1.add(new JLabel("")); jp1.add(jrb4); jp1.add(jb);
            jb.addActionListener(this);
            this.add(jp1,BorderLayout.NORTH);
            this.add(list,BorderLayout.CENTER);        
        }
        public void setThread1(Thread[] mt) {
            this.thread = mt;
        }
        public void actionPerformed(ActionEvent e) {
            iflag = 0;
            try {
                money = Integer.parseInt(jtf.getText());
                if(money > iMoney || iMoney <= 0) {
                    iflag = 1;
                }
                if(money <= 0) {
                    iflag = 3;
                }
            } catch(Exception ex) {
                iflag = 2;
            }
            if(iflag == 0) {
                jlError.setText("");
                Random r = new Random();
                list.clear();
                no = 1;
                int num1,num2,num3,num4;
                num1 = r.nextInt(4);
                if(jrb1.isSelected()) {
                    select = "1号马";
                }
                else if(jrb2.isSelected()) {
                    select = "2号马";
                }
                else if(jrb3.isSelected()) {
                    select = "3号马";
                }
                else if(jrb4.isSelected()) {
                    select = "4号马";
                }
                while(true) {
                    num2 = r.nextInt(4);
                    if(num2 == num1) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
                while(true) {
                    num3 = r.nextInt(4);
                    if(num3 == num1 || num3 == num2) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
                while(true) {
                    num4 = r.nextInt(4);
                    if(num4 == num1 || num4 == num2 || num4 ==num3) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
                if(flag == 0) {
                    thread[num1].start();
                    thread[num2].start();
                    thread[num3].start();
                    thread[num4].start();
                    flag = 1;
                    jb.setLabel("继续");
                    jb.setEnabled(false);
                }
                else if(flag == 1) {
                    thread[num1].resume();
                    thread[num2].resume();
                    thread[num3].resume();
                    thread[num4].resume();
                    jb.setLabel("继续");
                    jb.setEnabled(false);
                }
                else if(iflag == 1) {
                    jlError.setText("您的资金不足");
                }
                else if(iflag == 2) {
                    jlError.setText("输入格式不正确");
                }
                else if(iflag == 3) {
                    jlError.setText("请正确输入金额");
                }
            }        
        }
        public static void setString(String str) {
            list.add("第" + no + "名是:" + str + "号马");
            no++;
            if(list.getItemCount() == 4) {
                String strs[] = list.getItem(0).split(":");
                if(strs[1].equals(select)) {
                    list.add("恭喜您猜对了");
                    iMoney += money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
                else {
                    list.add("您猜错了,下次再来");
                    iMoney -= money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
            }
            if(list.getItemCount() == 5) {
                jtf.requestFocus();
                jtf.selectAll();
                jb.setEnabled(true);
            }
        }
    }
      

  6.   

     public void actionPerformed(ActionEvent e) {     //此为实现按钮单击事件
            iflag = 0;
            try {
                money = Integer.parseInt(jtf.getText());
                if(money > iMoney || iMoney <= 0) {
                    iflag = 1;
                }
                if(money <= 0) {
                    iflag = 3;
                }
            } catch(Exception ex) {
                iflag = 2;
            }
              //以上代码为判断资金状态是否正确,如果资金不足iflag置1,输入的不是数字置为2,如果未下注置为3.
           
            if(iflag == 0) {   //如果下注正确执行以下代码
                jlError.setText("");
                Random r = new Random();
                list.clear();
                no = 1;
                int num1,num2,num3,num4;
                num1 = r.nextInt(4);
                //以下代码为取的用户选中的那号码,存在select中
                if(jrb1.isSelected()) {
                    select = "1号马";
                }
                else if(jrb2.isSelected()) {
                    select = "2号马";
                }
                else if(jrb3.isSelected()) {
                    select = "3号马";
                }
                else if(jrb4.isSelected()) {
                    select = "4号马";
                }
                //以下条码是产生一个0--3的随机数,并且直到num2!=num1时退出while
                while(true) {
                    num2 = r.nextInt(4);
                    if(num2 == num1) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
              //以下条码是产生一个0--3的随机数,并且直到num3!=num2!=num1时退出while
                while(true) {
                    num3 = r.nextInt(4);
                    if(num3 == num1 || num3 == num2) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
          //以下条码是产生一个0--3的随机数,并且直到num4!=num3!=num2!=num1时退出while(也即时参生的num1,num2,num3,num4四个随机数,值不相同.)
                while(true) {
                    num4 = r.nextInt(4);
                    if(num4 == num1 || num4 == num2 || num4 ==num3) {
                        continue;
                    }
                    else {
                        break;
                    }
                }
                if(flag == 0) {//判断线程的状态(未启动)
                    //启动四个线程
                    thread[num1].start();
                    thread[num2].start();
                    thread[num3].start();
                    thread[num4].start();
                    flag = 1;
                    jb.setLabel("继续");
                    jb.setEnabled(false);
                }
                else if(flag == 1) { //判断线程的状态(已启动)
                    //暂停四个线程
                    thread[num1].resume();
                    thread[num2].resume();
                    thread[num3].resume();
                    thread[num4].resume();
                    jb.setLabel("继续");
                    jb.setEnabled(false);
                }   
                else if(iflag == 1) {
                    jlError.setText("您的资金不足");
                }
                else if(iflag == 2) {
                    jlError.setText("输入格式不正确");
                }
                else if(iflag == 3) {
                    jlError.setText("请正确输入金额");
                }
            }        
        }
      

  7.   

     public static void setString(String str) {
            list.add("第" + no + "名是:" + str + "号马"); //在list列表加入一个值,每一名加在第一个位置,
            no++;
            //如果list有4个项,即为四匹码都到达终点,
            if(list.getItemCount() == 4) {
                //以下为取的list中第一项中的字符以:为分割符其中strs[0]值为"第" + no + "名是strs[1]值为str + "号马"
                String strs[] = list.getItem(0).split(":");
                 //如果strs[1](str + "号马")与你所选中的值相同,则为中奖
                if(strs[1].equals(select)) {
                    list.add("恭喜您猜对了");
                    iMoney += money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
                else {
                    list.add("您猜错了,下次再来");
                    iMoney -= money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
            }
            if(list.getItemCount() == 5) {
                jtf.requestFocus();
                jtf.selectAll();
                jb.setEnabled(true);
            }
        }
      

  8.   

    个人认为:
    public static void setString(String str) {
            list.add("第" + no + "名是:" + str + "号马");
            no++;
    应改为:
    no++;
     list.add("第" + no + "名是:" + str + "号马");
      

  9.   

    我是按照您说的去改的(wang_yingwei) ,但是好象没有变化?
      

  10.   


    改为:
    public static void setString(String str) {        
           list.add("第" + no + "名是:" + str + "号马");
            no++;
            if(list.getItemCount() == 4) {
                String strs[] = list.getItem(0).split(":"); //你以前的这里错了。
                if(strs[1].equals(select)) {
                    list.add("恭喜您猜对了");
                    iMoney += money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
                else {
                    list.add("您猜错了,下次再来");
                    iMoney -= money;
                    jlMoney.setText("您的资金为:" + iMoney);
                }
            }
            if(list.getItemCount() == 5) {
                jtf.requestFocus();
                jtf.selectAll();
                jb.setEnabled(true);
            }
        }
      

  11.   

    请问一下,为什么只不过是一个分号,却会有这么大的作用,请教一下您的QQ wang_yingwei ,非常感谢!