请问路过的明白人swing和applet不是一个东西吗?
能不能给个最简单的DEMO/
能不能给个最简单的DEMO/
解决方案 »
- 请问如何把 NetBeans 编写的程序生成一个可以执行的文件
- 应用程序会有长达仅20秒的停顿
- 求java向ldap中添加条目的示例代码
- Class.forName的作用
- 这个简历写的怎么样,应该改改哪里,大家帮忙看看
- java怎么启动outlook?
- 如何解决下中文字体难看的问题????????
- 请教String类型的转义字符表达与SQL语句。
- 双击JTree的某个节点,如何产生响应啊?
- !!!!!!!!!!!急需 JBuilder 5 的序列号!!!!!!!!!!!!!!!
- JAVA程序如何把excel文件导入oracle数据库?
- Jdk中的AudioPlayer有Bug?调用后不能返回??程序会一只运行◎!
就是把类后边的extends Applet去掉 那这个程序就变成swing了??
import javax.swing.*;
public class HelloWorldSwing {
/**
* 创建并显示GUI。 出于线程安全的考虑,
* 这个方法在事件调用线程中调用。
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label); //Display the window.
frame.pack();
frame.setVisible(true);
} public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}Applet或Java小应用程序是一种在Web环境下,运行于客戶端的Java程序組件。它也是1990年代中期,Java在诞生后得以一炮走红的功臣之一。通常,每个Applet的功能都比较单一(例如仅用于显示一个舞动的Logo),因此它被称作“小应用程序”。
Applet必须运行于某个特定的“容器”,这个容器可以是浏览器本身,也可以是通过各种外挂程式,或者包括支持Applet的移动设备在內的其他各种程序来运行。与一般的Java应用程序不同,Applet不是通过main方法來运行的。在运行时Applet通常会与用戶进行互动,显示动态的画面,并且还会遵循严格的安全检查,阻止潜在的不安全因素(例如根据安全策略,限制Applet对客戶端文件系统的访问)。
Java AppletJava Applet用於HTML文件。HTML代碼:<html>
<head>
<title>Hello World</title>
</head>
<body>
HelloWorld Program says:
<applet code="HelloWorld.class" width="600" height="100">
</applet>
</body>
</html>Java代碼:import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hello, world!", 100, 50);
}
}//java HelloWorld
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello, world!");
}
}
Applet是在写网页结构,而Swing是进行GUI开发。
下面是Applet程序和swing组件混合使用的DEMO:import javax.swing.*;
import java.awt.event.*;
public class ButtonApplet extends JApplet {
JButton button;
public void init() {
button = new JButton("开始");
button.AddActionListener(new handle());
add(button);
}
class handle implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(button.getText() == "开始")
button.setText = "结束";
else
button.setText = "开始";
}
}
}下面是网页显示<html>
<head>
<title>Applet Demo</title>
</head>
<body>
<applet code="ButtonApplet.class" width="400" height="400"></applet>
</body>
</html>
而APPLET是内嵌于浏览器执行的(当然,也可以用 appletviewer进行测试和运行),可以象应用程序一样在APPLET中使用awt,swing的组件。
从继承关系上可以看出applet继承于jpanel
一个不是特别恰当的比喻就是,applet跟网页里flash程序(比如算智商啊什么的)差不多。
都是嵌在网页里的程序。
至于swing,
你做带界面的程序,就需要按钮啊,输入框啊,标签啊,单选框啊,复选框啊等等,就是界面里的那些东西,
把这么一堆东西放在一起,组成一个公司就是swing.