这是我调好的程序,测试成功package untitled5;import java.awt.*;
import javax.swing.*;//import sun.java2d.loops.CustomComponent;import java.awt.event.*;public class TJButton
extends JApplet { //结果不对 啊郁闷!!!
JButton button1, button2, button3; Icon metalIcon = new ImageIcon("metal.gif");
Icon motifIcon = new ImageIcon("motif.gif");
Icon windowIcon = new ImageIcon("window.gif"); String metallicLF = "javax.swing.plaf.metal.MetalLookAndFeel";
String motifLF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
String windowLF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; public void init() { GridLayout grid = new GridLayout(1, 3, 5, 5);
this.getContentPane().setLayout(grid);
this.getContentPane().setBackground(Color.lightGray); button1 = new JButton("Java L&F", metalIcon);
button1.setVerticalTextPosition(SwingConstants.BOTTOM);
button1.setHorizontalTextPosition(SwingConstants.CENTER);
button1.setMnemonic('J');
button1.setEnabled(false);
button1.setActionCommand(metallicLF);
CustomListener c1 = new CustomListener(this);
button1.addActionListener(c1);
this.getContentPane().add(button1); button2 = new JButton("Motif L&F", motifIcon);
button2.setVerticalTextPosition(SwingConstants.BOTTOM);
button2.setHorizontalTextPosition(SwingConstants.CENTER);
button2.setMnemonic('M');
button2.setActionCommand(motifLF);
CustomListener c2 = new CustomListener(this);
button2.addActionListener(c2);
this.getContentPane().add(button2); button3 = new JButton("Window L&F", windowIcon);
button3.setVerticalTextPosition(SwingConstants.BOTTOM);
button3.setHorizontalTextPosition(SwingConstants.CENTER);
button3.setMnemonic('W');
button3.setActionCommand(windowLF);
CustomListener c3 = new CustomListener(this);
button3.addActionListener(c3);
this.getContentPane().add(button3); } class CustomListener
implements ActionListener { TJButton testApplet = null;
public CustomListener(TJButton testApplet) {
this.testApplet = testApplet; } public void actionPerformed(ActionEvent evt) {
String LF = evt.getActionCommand();
try {
UIManager.setLookAndFeel(LF);
SwingUtilities.updateComponentTreeUI(testApplet);
JButton button = (JButton) evt.getSource();
button.setEnabled(false);
updateStatus(button); }
catch (Exception e) {
System.err.println("Look and Feel not set for " + LF + "!"); }
} public void updateStatus(JButton button) {
if (button == button1) {
button2.setEnabled(true);
button3.setEnabled(true);
}
else if (button == button2) {
button1.setEnabled(true);
button3.setEnabled(true);
}
else if (button == button3) {
button1.setEnabled(true);
button2.setEnabled(true); }
}
}}
import javax.swing.*;//import sun.java2d.loops.CustomComponent;import java.awt.event.*;public class TJButton
extends JApplet { //结果不对 啊郁闷!!!
JButton button1, button2, button3; Icon metalIcon = new ImageIcon("metal.gif");
Icon motifIcon = new ImageIcon("motif.gif");
Icon windowIcon = new ImageIcon("window.gif"); String metallicLF = "javax.swing.plaf.metal.MetalLookAndFeel";
String motifLF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
String windowLF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; public void init() { GridLayout grid = new GridLayout(1, 3, 5, 5);
this.getContentPane().setLayout(grid);
this.getContentPane().setBackground(Color.lightGray); button1 = new JButton("Java L&F", metalIcon);
button1.setVerticalTextPosition(SwingConstants.BOTTOM);
button1.setHorizontalTextPosition(SwingConstants.CENTER);
button1.setMnemonic('J');
button1.setEnabled(false);
button1.setActionCommand(metallicLF);
CustomListener c1 = new CustomListener(this);
button1.addActionListener(c1);
this.getContentPane().add(button1); button2 = new JButton("Motif L&F", motifIcon);
button2.setVerticalTextPosition(SwingConstants.BOTTOM);
button2.setHorizontalTextPosition(SwingConstants.CENTER);
button2.setMnemonic('M');
button2.setActionCommand(motifLF);
CustomListener c2 = new CustomListener(this);
button2.addActionListener(c2);
this.getContentPane().add(button2); button3 = new JButton("Window L&F", windowIcon);
button3.setVerticalTextPosition(SwingConstants.BOTTOM);
button3.setHorizontalTextPosition(SwingConstants.CENTER);
button3.setMnemonic('W');
button3.setActionCommand(windowLF);
CustomListener c3 = new CustomListener(this);
button3.addActionListener(c3);
this.getContentPane().add(button3); } class CustomListener
implements ActionListener { TJButton testApplet = null;
public CustomListener(TJButton testApplet) {
this.testApplet = testApplet; } public void actionPerformed(ActionEvent evt) {
String LF = evt.getActionCommand();
try {
UIManager.setLookAndFeel(LF);
SwingUtilities.updateComponentTreeUI(testApplet);
JButton button = (JButton) evt.getSource();
button.setEnabled(false);
updateStatus(button); }
catch (Exception e) {
System.err.println("Look and Feel not set for " + LF + "!"); }
} public void updateStatus(JButton button) {
if (button == button1) {
button2.setEnabled(true);
button3.setEnabled(true);
}
else if (button == button2) {
button1.setEnabled(true);
button3.setEnabled(true);
}
else if (button == button3) {
button1.setEnabled(true);
button2.setEnabled(true); }
}
}}
解决方案 »
- 在线等,速度结贴
- import Object.Mine; 报错说 软件包 Object 找不到 怎么搞的
- 用netbean编写java应用程序项目时,主类中用到的图片和txt,应该放在哪个文件夹里面??
- java线程中的同步
- 求助,在DOM解析HTML时如何得知TABLE 节点是否是嵌套关系
- 我有thinking in java中文3版,谁要?
- 求助 shh E:/apache-tomcat-6.0.26/webapps/myshopping/WEB-INF/classes/struts.xml:4:
- 在线求救!!!在线求救!!!在线求救!!!在线求救!!!
- 请教各位高手!
- 如何制作对话框!如:dialog box
- 如何将文件名为aaa\abc\efg\aa.xls转换成aaa\\abc\\efg\\aa.xls
- 关于JScrollPane的问题
String metallicLF = "javax.swing.plaf.metal.MetalLookAndFeel";
String motifLF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
String windowLF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
定义都有问题,。字符串内容不对