偶调试了一些<<Java编程思想2>>P568的程序,好像没有图形的风格呀,只有一个DOS的运行框就没反应了?请问这是怎么回事? 谢谢!!!
解决方案 »
- 求解java中三元表达式的运行原理? 急!!!
- 不明白这个foreach语法。。。。
- 帮我看看这段代码,运行的时候为什么cpu占用率达到了100%哪里出问题了吗,里面的其他一些类不用管应该就是这段代码出问题了
- 请教classpath问题,谢谢
- 调查一下:大家在平时的项目中使用junit做测试的多吗?
- 如何从如"200304"获得三个月前的月份如"200301"?
- 为何这个程序输入的三个数据只能是n1<n1<n3才可以比较,否则就不可以比较大小;急
- 关于log4j的问题,欢迎大家讨论,高分相送
- 如何用Javascript程序控制一个Applet的行为???
- 构造函数 main函数 静态函数 有什么区别啊
- java怎么打开excel文件呀 .例如:c:\demo.xls
- 一个关于ArrayList重新组合排序的问题
编程思想讲的不是这方面的内容啊,你应该看java的swing编程
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import com.bruceeckel.swing.*;public class LookAndFeel extends JFrame {
String[] choices = {
"eeny", "meeny", "minie", "moe", "toe", "you"
};
Component[] samples = {
new JButton("JButton"),
new JTextField("JTextField"),
new JLabel("JLabel"),
new JCheckBox("JCheckBox"),
new JRadioButton("Radio"),
new JComboBox(choices),
new JList(choices),
};
public LookAndFeel() {
super("Look And Feel");
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
for(int i = 0; i < samples.length; i++)
cp.add(samples[i]);
}
private static void usageError() {
System.out.println(
"Usage:LookAndFeel [cross|system|motif]");
System.exit(1);
}
public static void main(String[] args) {
if(args.length == 0) usageError();
if(args[0].equals("cross")) {
try {
UIManager.setLookAndFeel(UIManager.
getCrossPlatformLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace(System.err);
}
} else if(args[0].equals("system")) {
try {
UIManager.setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace(System.err);
}
} else if(args[0].equals("motif")) {
try {
UIManager.setLookAndFeel("com.sun.java."+
"swing.plaf.motif.MotifLookAndFeel");
} catch(Exception e) {
e.printStackTrace(System.err);
}
} else usageError();
// Note the look & feel must be set before
// any components are created.
Console.run(new LookAndFeel(), 300, 200);
}
}
还有,这个程序是要对main()传参的,本例用自己写的类Console解决了这个问题,如果你没有这个类的话只能自己在控制行里自己写;
我把它改了一下完全可一啊;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;public class LookAndFeel extends JFrame {
String[] choices = {
"eeny", "meeny", "minie", "moe", "toe", "you"
};
Component[] samples = {
new JButton("JButton"),
new JTextField("JTextField"),
new JLabel("JLabel"),
new JCheckBox("JCheckBox"),
new JRadioButton("Radio"),
new JComboBox(choices),
new JList(choices),
};
public LookAndFeel() {
super("Look And Feel");
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
for(int i = 0; i < samples.length; i++)
cp.add(samples[i]);
}
private static void usageError() {
System.out.println(
"Usage:LookAndFeel [cross|system|motif]");
System.exit(1);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch(Exception e) {
e.printStackTrace(System.err);
}
LookAndFeel a=new LookAndFeel();
a.setSize(600,300);
a.setVisible(true);
}
}