当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: <tr onfocusin="setcolor(this)" onfocusout="clearcolor(this)" ondblclick="openwin(abc.asp,300,500)"> 比如上面这个tr,我应该怎样做 ......
 ·奇怪的现象,大家快帮帮忙    »显示摘要«
    摘要: 我有网域网内服务器上的wwwroot目录的读写权,为什么有文件不能复制上去? 老是提示:无法复制xxx:拒绝访问。源文件可能正被使用。 我重新启动iis服务或重新启动服务器也没有用。还是老情况。 ......


一个关于背景颜色改变的问题

这是一个改变背景颜色的程序,但运行后颜色没改变阿?  
  请帮忙看看。谢谢  
   
  import   java.awt.*;  
  import   java.awt.event.*;  
  import   javax.swing.*;  
   
  class   FirstPanel   extends   JPanel  
              implements   ActionListener  
  {           public   FirstPanel()  
              {             JButton   redButton   =   new   JButton("Red");  
                            JButton   blueButton   =   new   JButton("Blue");  
                            JButton   yellowButton   =   new   JButton("Yellow");  
   
                            add(redButton);  
                            add(blueButton);  
                            add(yellowButton);  
   
                            redButton.addActionListener(this);  
                            blueButton.addActionListener(this);  
                            yellowButton.addActionListener(this);  
              }  
   
              public   void   actionPerformed(ActionEvent   evt)  
              {           Object   source   =   evt.getSource();  
                          Color   color   =   getBackground();  
                          if   (source   ==   redButton)   color   =   Color.red;  
                          else   if   (source   ==   blueButton)   color   =   Color.blue;  
                          else   if   (source   ==   yellowButton)   color   =   Color.yellow;  
                          setBackground(color);  
                          repaint();  
              }  
              private   JButton   redButton;  
              private   JButton   blueButton;  
              private   JButton   yellowButton;  
  }  
  class   FirstFrame   extends   JFrame  
  {           public   FirstFrame()  
              {             setTitle("FirstFrame");  
                            setSize(300,   200);  
                            addWindowListener(new   WindowAdapter()  
                            {         public   void   windowClosing(WindowEvent   e)  
                                      {             System.exit(0);  
                                      }  
                            });  
                     
                      Container   contentPane   =   getContentPane();  
                      contentPane.add(new   FirstPanel());  
              }  
  }  
   
  public   class   FirstTest  
  {             public   static   void   main(String[]   args)  
                {             JFrame   frame   =   new   FirstFrame();  
                              frame.setVisible(true);  
                }  
  }

NO.1   作者: shihb

import   java.awt.*;  
  import   java.awt.event.*;  
  import   javax.swing.*;  
   
  class   FirstPanel   extends   JPanel  
              implements   ActionListener  
  {           public   FirstPanel()  
              {             JButton   redButton   =   new   JButton("Red");//你在这个地方不应该再定义三个JButton,你把这三个button前的JButton去掉就可以了!你试试!  
                            JButton   blueButton   =   new   JButton("Blue");  
                            JButton   yellowButton   =   new   JButton("Yellow");  
   
                            add(redButton);  
                            add(blueButton);  
                            add(yellowButton);  
   
                            redButton.addActionListener(this);  
                            blueButton.addActionListener(this);  
                            yellowButton.addActionListener(this);  
              }  
   
              public   void   actionPerformed(ActionEvent   evt)  
              {           Object   source   =   evt.getSource();  
                          Color   color   =   getBackground();  
                          if   (source   ==   redButton)   color   =   Color.red;  
                          else   if   (source   ==   blueButton)   color   =   Color.blue;  
                          else   if   (source   ==   yellowButton)   color   =   Color.yellow;  
                          setBackground(color);  
                          repaint();  
              }  
              private   JButton   redButton;  
              private   JButton   blueButton;  
              private   JButton   yellowButton;  
  }  
  class   FirstFrame   extends   JFrame  
  {           public   FirstFrame()  
              {             setTitle("FirstFrame");  
                            setSize(300,   200);  
                            addWindowListener(new   WindowAdapter()  
                            {         public   void   windowClosing(WindowEvent   e)  
                                      {             System.exit(0);  
                                      }  
                            });  
                     
                      Container   contentPane   =   getContentPane();  
                      contentPane.add(new   FirstPanel());  
              }  
  }  
   
  public   class   FirstTest  
  {             public   static   void   main(String[]   args)  
                {             JFrame   frame   =   new   FirstFrame();  
                              frame.setVisible(true);  
                }  
  }  
 

NO.2   作者: drinkant

错误在于  
              private   JButton   redButton;  
              private   JButton   blueButton;  
              private   JButton   yellowButton;  
  然后构造器中再  
                            JButton   redButton   =   new   JButton("Red");  
                            JButton   blueButton   =   new   JButton("Blue");  
                            JButton   yellowButton   =   new   JButton("Yellow");  
  明白   ?   一开始偶也被迷惑了.   .   .   .   .  
   
 


    摘要: 想要分析一下该函数的实现。多谢了。 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE