极菜问题:在JButton上加Icon hehe~~java是不认.ico的,要用.gif格式的图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.*;import java.awt.*;import java.awt.event.*;class Mywindow extends JFrame implements ActionListener{ JButton button1,button2,button3;JTextArea text;Icon icon; Mywindow() {setSize(200,200);setVisible(true); Container con=getContentPane(); text=new JTextArea(); con.setLayout(new GridLayout(1,4)); icon=new ImageIcon("tom.jpg"); button1=new JButton("Boy",icon); button2=new JButton("Girl"); button3=new JButton("friend",new ImageIcon("tom1.jpg")); button1.setVerticalTextPosition(AbstractButton.TOP); button1.setMnemonic('b'); con.add(button1);con.add(button2);con.add(button3);con.add(text); button1.addActionListener(this);button3.addActionListener(this); addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}}); } public void actionPerformed(ActionEvent e) {if(e.getSource()==button1) { text.setText(button1.getText()+button2.getText()); button2.setIcon(button1.getIcon()); button2.setHorizontalTextPosition(AbstractButton.RIGHT);button3.setEnabled(false); } else if(e.getSource()==button3) { text.append(button3.getText()); button2.setIcon(button3.getIcon()); } }}public class Example25_10{ public static void main(String args[]) { Mywindow win=new Mywindow();win.pack(); }}在java中是这么用的 请大家帮帮忙程序云行后内容写不进文件 问下关于多态的问题 如何拿到数据库自动生成的主键值呢? 命令提示符下“java”命令不能用(非环境变量设置问题) 跪求Java高手解决状态栏问题 请问各位大人:如何把文本中的非中文字符过滤掉 请问带有xxxxx_skel.class 和 yyyyy_stub.class 的文件是如何生成的呢? 为什么发送中文消息对方就显示乱码?? $$$$$这里有学java已就业的吗?¥¥¥ apache-tomcat 4.0 运行 html 页的问题,急 大家好,希望和大家共同交流JAVA学习经验,我的QQ:4931851 关于多线程,急急急!
class Mywindow extends JFrame implements ActionListener
{ JButton button1,button2,button3;JTextArea text;Icon icon;
Mywindow()
{setSize(200,200);setVisible(true);
Container con=getContentPane();
text=new JTextArea();
con.setLayout(new GridLayout(1,4));
icon=new ImageIcon("tom.jpg");
button1=new JButton("Boy",icon); button2=new JButton("Girl");
button3=new JButton("friend",new ImageIcon("tom1.jpg"));
button1.setVerticalTextPosition(AbstractButton.TOP);
button1.setMnemonic('b');
con.add(button1);con.add(button2);con.add(button3);con.add(text);
button1.addActionListener(this);button3.addActionListener(this);
addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e)
{System.exit(0);}});
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==button1)
{ text.setText(button1.getText()+button2.getText());
button2.setIcon(button1.getIcon());
button2.setHorizontalTextPosition(AbstractButton.RIGHT);button3.setEnabled(false);
}
else if(e.getSource()==button3)
{ text.append(button3.getText()); button2.setIcon(button3.getIcon());
}
}
}
public class Example25_10
{ public static void main(String args[])
{ Mywindow win=new Mywindow();win.pack();
}
}
在java中是这么用的