请问swing和applet不一样吗? 请问路过的明白人swing和applet不是一个东西吗?能不能给个最简单的DEMO/ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 简单点说swing可以用来构建JAVA应用程序,完全可以独立于浏览器运行,而APPLET是内嵌于浏览器执行的(当然,也可以用 appletviewer进行测试和运行),可以象应用程序一样在APPLET中使用awt,swing的组件。 还是有点不明白就是把类后边的extends Applet去掉 那这个程序就变成swing了?? Swing 是一个为Java设计的GUI工具包。Swing 是 JAVA基础类的一部分。Swing包括了图形用戶界面 (GUI) 器件 如:文本框,按钮,分隔窗格和表等。SWING提供许多比AWT更好的屏幕显示元素。它们用纯Java实现,所以同Java本身一样可以跨平台运行,同AWT不一样。 它们都是JFC的一部分,支持可更换的面板和主题,然而不是真的使用原生平台提供的设备,而是仅仅在表面上模仿他们。這意味着你可以在任意平台上使用JAVA支持的任意面板。轻量級元件的缺点则是执行速度较慢,优点就是可以在所有平台上采用统一的行为。//HelloWorldSwing.java代码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 HelloWorldpublic class Hello{ public static void main(String[] args) { System.out.println("Hello, world!"); }} 你在写程序的时候,你可以extends Applet,也可以extends JApplet,这说明Applet是不同的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的小应用程序可以在网页上运行 就是把extends Applet 去掉,写main方法直接写界面就是个swing程序了?? 简单点说swing可以用来构建JAVA应用程序,完全可以独立于浏览器运行,而APPLET是内嵌于浏览器执行的(当然,也可以用 appletviewer进行测试和运行),可以象应用程序一样在APPLET中使用awt,swing的组件。从继承关系上可以看出applet继承于jpanel 不一定对,供你参考。放在网页里执行行的java程序,就是applet,一个不是特别恰当的比喻就是,applet跟网页里flash程序(比如算智商啊什么的)差不多。都是嵌在网页里的程序。至于swing,你做带界面的程序,就需要按钮啊,输入框啊,标签啊,单选框啊,复选框啊等等,就是界面里的那些东西,把这么一堆东西放在一起,组成一个公司就是swing. 数组 字符串的问题 关于JMenuBar中setHelpMune()的问题 请帮个忙。初学者。所以可能问题比较幼稚。请见晾 AGENT中JAVA语法问题 private,public权限问题! 怎么运行一个jar包中的main 类,有manifest.mf这个文件,但是这个文件中没指定主类 如何使JB代码编辑时支持鼠标中间键 win2000下编译java程序看不到运行结果的问题,今天解决加到100分!!! 如何通过java收发邮件? 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.