都来帮帮忙啦,这里分多:) 呵呵,我能力以外,初学,有些地方看不懂。>_< 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.*;import javax.swing.*;import java.awt.event.*;public class KeyTest{ public static void main( String args[] ) { KeyFrame frame=new KeyFrame();//设置退出进程的windowlistener frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.show(); }}//定义框架类class KeyFrame extends JFrame{//在框架类的constructor里设置框架属性,并且加载Panel,在 Panel上装按钮一个 public KeyFrame() { setBounds(100,100,400,400); setTitle("KeyTest"); Container container=getContentPane(); JPanel bPanel=new JPanel(); bPanel.setFocusable(false); container.add(bPanel); ColorAction ca=new ColorAction(Color.yellow,"Yellow"); JButton but=new JButton(ca); bPanel.add(but); }//这是按钮对象关联的Action类定义 class ColorAction extends AbstractAction { public ColorAction(Color color,String string) { putValue("color",color); putValue(NAME,string); }//actionPerformed意思是Action触发后,改变背景颜色至黄色 public void actionPerformed(ActionEvent ae) { Color bgc=(Color)getValue("color"); setBackground(bgc); repaint(); } }}各位哥哥姐姐,已经注释了,满意了嘛:) import java.awt.*;import javax.swing.*;import java.awt.event.*;public class KeyTest{ public static void main( String args[] ) { KeyFrame frame=new KeyFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.show(); }}class KeyFrame extends JFrame{ JPanel bPanel=new JPanel(); public KeyFrame() { setBounds(100,100,400,400); setTitle("KeyTest"); Container container=getContentPane(); bPanel.setFocusable(false); container.add(bPanel); ColorAction ca=new ColorAction(Color.yellow,"Yellow"); JButton but=new JButton(ca); bPanel.add(but); } class ColorAction extends AbstractAction { public ColorAction(Color color,String string) { putValue("color",color); putValue(NAME,string); } public void actionPerformed(ActionEvent ae) { Color bgc=(Color)getValue("color"); bPanel.setBackground(bgc); repaint(); } }} java if 语句问题 菜鸟提问 wait()要释放锁,是吗?那么如果一个synchronized()的代码块中,没有wait()就永远不释放锁吗?? DEBUG问题 死锁的概念不懂 提两个小问题。 怎么用java mail disposition-notification;邮件? 打印和打印预览的思路 请教JSP做流量访问系统中的IP显示问题??急~~~~ 怎么给Jface的ApplicationWindow加个窗口图标? 使用JDBC连接DB2(Rs\6000、AIX)出现问题,附源码!请指教? 一个小问题 大家帮看看 使用Java的勇气号都动不了啦,放弃java吧
import javax.swing.*;
import java.awt.event.*;public class KeyTest
{
public static void main( String args[] )
{
KeyFrame frame=new KeyFrame();
//设置退出进程的windowlistener
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.show();
}
}
//定义框架类
class KeyFrame extends JFrame
{
//在框架类的constructor里设置框架属性,并且加载Panel,在 Panel上装按钮一个
public KeyFrame()
{
setBounds(100,100,400,400);
setTitle("KeyTest");
Container container=getContentPane();
JPanel bPanel=new JPanel();
bPanel.setFocusable(false);
container.add(bPanel);
ColorAction ca=new ColorAction(Color.yellow,"Yellow");
JButton but=new JButton(ca);
bPanel.add(but);
}
//这是按钮对象关联的Action类定义
class ColorAction extends AbstractAction
{
public ColorAction(Color color,String string)
{
putValue("color",color);
putValue(NAME,string);
}
//actionPerformed意思是Action触发后,改变背景颜色至黄色
public void actionPerformed(ActionEvent ae)
{
Color bgc=(Color)getValue("color");
setBackground(bgc);
repaint();
}
}
}各位哥哥姐姐,已经注释了,满意了嘛:)
import javax.swing.*;
import java.awt.event.*;public class KeyTest
{
public static void main( String args[] )
{
KeyFrame frame=new KeyFrame();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.show();
}
}class KeyFrame extends JFrame
{
JPanel bPanel=new JPanel();
public KeyFrame()
{
setBounds(100,100,400,400);
setTitle("KeyTest");
Container container=getContentPane(); bPanel.setFocusable(false);
container.add(bPanel);
ColorAction ca=new ColorAction(Color.yellow,"Yellow");
JButton but=new JButton(ca);
bPanel.add(but);
}
class ColorAction extends AbstractAction
{
public ColorAction(Color color,String string)
{
putValue("color",color);
putValue(NAME,string);
}
public void actionPerformed(ActionEvent ae)
{
Color bgc=(Color)getValue("color");
bPanel.setBackground(bgc);
repaint();
}
}
}