读书人

关于java编程思想的一个源代码,该怎么

发布时间: 2012-01-31 21:28:42 作者: rapoo

关于java编程思想的一个源代码
import javax.swing.*;
import java.awt.*;
import javawork.swing.*;
class Button1 extends JApplet
{
private JButton
b1 =new JButton( "Button1 "),
b2 =new JButton( "Button2 ");
public void init()
{
Container cp = getContentPane();
//FlowLayOut使得控件可以在窗体上从左到右,从上到下连续均匀分布
cp.setLayout(new FlowLayout());
cp.add(b1);
cp.add(b2);
}
public static void main(String [] args)
{
Console.run(new Button1(),200,100);
}
}
其中import javawork.swing.*;是从com.bruceeckel.swing 那里复制过来的
我运行后 为啥界面没有那两个按钮呢???


[解决办法]
我的有显示啊...
Console是这个

import javax.swing.*;
import java.awt.event.*;

public class Console {
// Create a title string from the class name:
public static String title(Object o) {
String t = o.getClass().toString();
// Remove the word "class ":
if(t.indexOf( "class ") != -1)
t = t.substring(6);
return t;
}
public static void
run(JFrame frame, int width, int height) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
frame.setVisible(true);
}
public static void
run(JApplet applet, int width, int height) {
JFrame frame = new JFrame(title(applet));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width, height);
applet.init();
applet.start();
frame.setVisible(true);
}
public static void
run(JPanel panel, int width, int height) {
JFrame frame = new JFrame(title(panel));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width, height);
frame.setVisible(true);
}
} ///:~
[解决办法]
那个think in java 3th是jdk1.4.2下的代码,
1.5应该没问题的

咱俩代码都一样结果不一样??
不太可能吧...
你在复制一遍试试吧

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Console {
// Create a title string from the class name:
public static String title(Object o) {
String t = o.getClass().toString();
// Remove the word "class ":
if(t.indexOf( "class ") != -1)
t = t.substring(6);
return t;
}
public static void
run(JFrame frame, int width, int height) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
frame.setVisible(true);
}
public static void
run(JApplet applet, int width, int height) {
JFrame frame = new JFrame(title(applet));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width, height);
applet.init();
applet.start();
frame.setVisible(true);
}
public static void
run(JPanel panel, int width, int height) {
JFrame frame = new JFrame(title(panel));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


frame.getContentPane().add(panel);
frame.setSize(width, height);
frame.setVisible(true);
}
} ///:~
class Button1 extends JApplet
{
private JButton
b1 =new JButton( "Button1 "),
b2 =new JButton( "Button2 ");
public void init()
{
Container cp = getContentPane();
//FlowLayOut使得控件可以在窗体上从左到右,从上到下连续均匀分布
cp.setLayout(new FlowLayout());
cp.add(b1);
cp.add(b2);
}
public static void main(String [] args)
{
Console.run(new Button1(),200,100);
}
}

读书人网 >J2SE开发

热点推荐