首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

图形界面运行有一处异常

2013-11-26 
图形界面运行有一处错误~求助import java.awt.*import java.awt.event.*import javax.swing.*import ja

图形界面运行有一处错误~求助
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class GUIshow extends JFrame implements ActionListener,ItemListener,ChangeListener,Runnable
{
    JPanel pNorth=new JPanel();
    JPanel pBottom=new JPanel();
    JPanel pTime=new JPanel();
    JLabel pic;
    ImageIcon img;
    Thread thread1;
    Label prompt,ptime,pscore;
    TextField question,score,time;
    JPasswordField answer;
    Checkbox look;
    JcomboBox size;
    Container c;
    JSlider jslcolor;
    int cValue;
    String[][]game=new String[3][3];
    int i;
    int scores=0,score0=0;
    int times=50;
    GUIshow()
    {
          this.setTitle("图形界面设计示例--竞猜小游戏");
          thread1=new Thread(this,"timing");
          c=getContentPane();
          c.setLayout(new BorderLayout());
          prompt=new Label("****有奖竞猜啦!****");
          size=new JComboBox();
          size.addItem("1");
          size.addItem("2");
          size.addItem("3");
          question=new TextField(20);
          look=new Checkbox("明码显示密码",false);
          answer=new JPasswordField(10);
          PTime.setFont(new Font("黑体",Font.PLAIN,18));
          PTime.setForeground(Color.red);
          Ptime=new Label("剩余时间:");
          time=new TextField(6);
          psocre=new Label("目前得分:");
          score=new Textfield("0");
          pNorth.add(prompt);
          pNorth.add(size);
          pNorth.add(question);
          pNorth.add(look);
          pNorth.add(answer);
          look.addItemListener(this);
          size.addItemListener(this);
          c.add(pNorth,BorderLayout.NORTH);
          pTime.setLayout(new GridLayout(8,1));
          pTime.add(ptime);
          pTime.add(time);
          pTime.add(pscore);
          pTime.add(score);
          c.add(pTime,BorderLayout.EAST);
          img=new ImageIcon("normal.gif");
          pic=new JLabel(img);
          c.add(pic.BorderLayout.CENTER);
          jslcolor=new JSlider(JSlider.HORIZONTAL,0,255,100);
          jslcolor.setMajorTickSpacing(50);
          jslcolor.setPaintLabels(true);
          Button btStart=new Button("开始游戏");
          Button btOk=new Button("确定");
          Button btCancel=new Button("退出");
          Button btReward=new Button("奖品");
          pBottom.add(jslcolor);
          pBottom.add(btStart);
          pBottom.add(btOk);
          pBottom.add(btReward);
          pBottom.add(btCanel);
          jslcolor.addChangeListener(this);
          btStart.addActionLiatener(this);
          btOk.addActionListener(this);


          btCancel.addActionListener(this);
          btReward.addActionListener(this);
          c.add(pBottom,BorderLayout.SOUTH);
          thread1.start();
          addWindowListener(new WindoeAdapter()
          {
               public void windowClosing(WindowEvent ew)
               {
                  System.exit(0);
               }
          });
          this.setBounds(200,50,600,400);
          this.setVisible(true);
          this.setResizable(false);
    }
    public void itemStateChanged(ItemEvent e)
    {
        if(e.getItemSelectable()instanceof JComboBox)
        {
           JComboBox temp;
           temp=(JComboBox)(e.getItemSelectbale());
           String s=temp.getSelectedItem().toString();
           i=Interger.parseInt(s);
           i=i-1;
           quesion.setText(getQuestion(i));
           switch(i)
           {
               case 0:
                  img=new ImageIcon("lfg.jpg");
                  break;
               case 1:
          img=new ImageIcon("hhit.jpg");
                  break;
               case 2:
          img=new ImageIcon("jsj.jpg");
                  break;

           }
           pic.setIcon(img);
        }
        if(e.getItemSelectable()instanceof Checkbox)
        {
           Checkbox ch=(Checkbox)(e.getItemSelectable());
           if(ch.getState())
           {
               answer.setEchoChar((char)0);
               answer.setText(game[i][1]);
           }
           else
           {
               answer.setEchoChar('*');
           }
        }
    }
    public void stateChanged(ChangeEvent es)
    {
        if(es.getSource()=jslcolor)
        {
            cValue=((JSlider)es.getSource()).getValue();
            pBottom.setBackground(new Color(cValue,250,cValue));
            pBottom.repaint();
        }
    }
    public void run()
    {
        try
        {
            while(times>0)
            {
                 Thread.sleep(1000);


                 times=times-1;
                 time.setText(""+times);
            }
            note();
        }
        catch(InterruptedException e)
        {}
    }
    public void actionPerformed(ActonEcent evt)
    {
         if(evt.getActionCommand().equals("开始游戏"))
         {
              question.setText(getQuestion(i));
              img=new ImageIcon("lfg.jpg");
              pic.setIcon(img);
              answer.setEchoChar((char)0);
              times=50;
              scores=0;
              time.setText(""+times);
              score.setText(""+scorses);
         }
         else if(evt.getActionCommand().equals("确定"))
         {
            if(String.valueOf(answer.getPassword()).equals(getAnswer(i)))
            {
               JOptionPane.showMessageDialog(null,"恭喜你回答正确!","友情提醒",1);
               score0=getScore(i);
               scores=scores+score0;
               score.setText(""+scores);
            }
            else
               JOptionPane.showMessageDialog(null,"对不起,回答错误!","友情提醒",0);
         }
         else if(evt.getActionCommand().equals("退出"))
         {
             System.exit(0);
         }
         else if(evt.getActionCommand().equals("奖品"))
     {
         img=new ImageIcon("gift.gif");
         pic.setIcon(img);
         }
    }
    public String getQuestion(int i)
    {
        game[0][0]="凌风阁是哪年建立的?";
        game[1][0]="淮海工学院是哪年成立的?";
        game[2][0]="计算机系是哪年成立的?";
        return game[i][0];
    }
    public String getAnswer(int i)
    {
        game[0][0]="2001";
    game[1][0]="1985";
    game[2][0]="2000";
        return game[i][0];
    }
    public int getScore(int i)
    {
        game[0][0]="40";
       game[1][0]="30";
       game[2][0]="30";
        return Integer.parseInt(game[i][2]);
    }
    public void note()
    {
       if(times==0&&!(String.valueOf(answer.getPassword().equals(getAnswer(i)))))
       {
           JoptionPane.showMessageDialog(null,"已经超时,请看答案!","友情提醒",1);
           answer.setEchoChar((char)0);
           answer.setText(game[i][1]);
       }
       if(scores==100)
          JOptionPane.showMessageDialog(null,"全部回答正确,你真棒!","友情提醒",1);
    }
}
public class XqqApplication_4-3


{
    public static void main(String args[])
    {
        new GUIshow();
    }
}
总是有错误:C:\Users\xuqianqian\Desktop\XqqApplication_4-3.java:223: 需要 '{'
public class XqqApplication_4-3
哪儿错了~~求助!! 图形界面 括号匹配
[解决办法]
我不懂这代码是你写的还是copy过来的,错误一堆,我都懒得改,

变量名一会大写一会小写! 判断语句用=
JComboBox 写成 JcomboBox
c.add(pic.BorderLayout.CENTER); 这啥意思?add里面要加的是Component,你这加个String啥意思???


[解决办法]
还有这个类名你还能用-???
XqqApplication_4-3???

热点排行