极菜问题:在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中是这么用的 jdk-6u35-linux-i586.bin 怎么处理java.lang.NoClassDefFoundError sqlserver2000 bcp导出数据问题。 java菜鸟 问题求解 我是java初学者,为什么我用ultraedit的时候关键字不变色啊? java连接SQLSERVER时出错需要帮助! !!!如果在运行过程中动态生成在运行后修改的CLASS? 我的按纽怎么加事件? 加载图像后怎么解决闪烁的问题呢? JAVA可以做论坛吗? 谁帮忙把Java Web Start的快捷方式发给我? 大家好,希望和大家共同交流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中是这么用的