JButton里有没有更改按钮上图片的set方法? 求助!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.*;import java.awt.event.*;import javax.swing.*;public class TestFrame extends JFrame{ private JButton btn = new JButton(); public TestFrame() { this.setLayout(new GridBagLayout()); //貌似需要GridBagLayout布局,不然btn旁边会有东西 btn.setIcon(new ImageIcon("up.jpg")); //初始时的图片 btn.setPressedIcon(new ImageIcon("down.jpg")); //按下去的图片 btn.setBorder(BorderFactory.createEmptyBorder()); //必须把边界设为空,否则btn四周会有东西 add(btn); } public static void main(String[] args) { JFrame frame = new TestFrame(); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }} 华为面试题,求完整答案 很简单的问题 swing和jface结合编程 如何向一个文本文件中写入String类型的数据. 如何获取一个数据库中所有表的名称 不用数据库保存数据?如何实现 java反射异常问题 那里有tomcat的下载? 请问如何在有符号数与无符号整数间进行转化--JAVA中有没有现成的类或方法 java初学者的提问?? 想用java写一个txt文本处理的程序 java新手急求大神解答!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestFrame extends JFrame
{
private JButton btn = new JButton();
public TestFrame()
{
this.setLayout(new GridBagLayout()); //貌似需要GridBagLayout布局,不然btn旁边会有东西
btn.setIcon(new ImageIcon("up.jpg")); //初始时的图片
btn.setPressedIcon(new ImageIcon("down.jpg")); //按下去的图片
btn.setBorder(BorderFactory.createEmptyBorder()); //必须把边界设为空,否则btn四周会有东西
add(btn);
}
public static void main(String[] args)
{
JFrame frame = new TestFrame();
frame.setSize(400, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}