setUI(new BasicButtonUI());

Ronys 2011-12-25 11:59:24
java 中有各种setUI 不懂什么意思。。。。。 我写了这个类:

public class MyButtonUI extends ButtonUI
{
public void paint(Graphics g, JComponent c)
{
g.setColor(Color.red);
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
}

在自定义的继承JButton类myButton中为什么要使用 setUI(new BasicButtonUI());没用到MyButtonUI啊,他们说setUI什么设置外观
...全文
128 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuowenhua123 2012-03-26
  • 打赏
  • 举报
回复

if(b.getIcon() != null) {
paintIcon(g,c,iconRect);
}



注意 BasicButtonUI 的 paint 中的这句话,这就是画图标的
如果你自己重写的方法里没有这句的话,图标当然显示不出来

重写BasicButtonUI类。。。
http://bk.chinaar.com/index.php?doc-view-1722
Ronys 2012-03-26
  • 打赏
  • 举报
回复
  if(b.getIcon() != null) {
paintIcon(g,c,iconRect);
}


注意 BasicButtonUI 的 paint 中的这句话,这就是画图标的
如果你自己重写的方法里没有这句的话,图标当然显示不出来

重写BasicButtonUI类。。。
http://bk.chinaar.com/index.php?doc-view-1722

登陆的代码如下 package denglu; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.plaf.basic.BasicButtonUI; import com.swtdesigner.SwingResourceManager; public class DengLu extends JFrame{ private JPasswordField pass; private static JTextField name; public void DengLu() { this.setTitle("登入窗口"); //设置登入窗口的属性参数 getContentPane().setLayout(null); setSize(453, 317); final JLabel label = new JLabel(); label.setHorizontalAlignment(SwingConstants.CENTER); label.setForeground(new Color(128, 128, 0)); label.setFont(new Font("华文彩云", Font.BOLD, 48)); label.setText("学生管理系统"); label.setBounds(0, 0, 447, 77); getContentPane().add(label); final JLabel label_1 = new JLabel(); label_1.setForeground(new Color(128, 128, 0)); label_1.setFont(new Font("", Font.BOLD, 22)); label_1.setText("用 户 名:"); label_1.setBounds(56, 101, 122, 32); getContentPane().add(label_1); final JLabel label_1_1 = new JLabel(); label_1_1.setForeground(new Color(255, 255, 255)); label_1_1.setFont(new Font("", Font.BOLD, 22)); label_1_1.setText("密 码:"); label_1_1.setBounds(56, 154, 122, 32); getContentPane().add(label_1_1); name = new JTextField();//用户名输入框 name.setBounds(205, 105, 155, 32); getContentPane().add(name); pass = new JPasswordField();//密码输入框 pass.setBounds(205, 158, 155, 32); pass.addKeyListener(new Key());//添加键盘监听 getContentPane().add(pass); final JButton button_1 = new JButton(); button_1.setForeground(new Color(255, 255, 255)); //设置按钮的事件处理 button_1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent arg0) { /*String s

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧