当前位置: 技术问答>java相关
高分征用!急!将APPLET转为APPLICATION
来源: 互联网 发布时间:2015-06-06
本文导语: 请留下EMAIL 源程序我给你发过去 | ioveme@etang.com | 如果没有从网页的参数,加上main函数就可以了: public static void main(String[] args) Frame frame = new Frame(); frame.setLayout(new BorderL...
请留下EMAIL
源程序我给你发过去
源程序我给你发过去
|
ioveme@etang.com
|
如果没有从网页的参数,加上main函数就可以了:
public static void main(String[] args)
Frame frame = new Frame();
frame.setLayout(new BorderLayout());
Applet applet= new XXX();
frame.add(applet);
frame.show();
}
public static void main(String[] args)
Frame frame = new Frame();
frame.setLayout(new BorderLayout());
Applet applet= new XXX();
frame.add(applet);
frame.show();
}
|
写下面这个class, invoke the run(...) in your class main() method.
///
import javax.swing.*;
import java.awt.event.*;
public class Console
{
//get the title string from the class name
public static String title(Object o)
{
String t = o.getClass().toString();
if(t.indexOf("class") != -1)
t = t.substring(6);
return t;
}
public static void setupClosing(JFrame frame)
{
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void run(JFrame frame, int width, int height)
{
setupClosing(frame);
frame.setSize(width,height);
frame.setVisible(true);
}
public static void run(JApplet applet, int width, int height)
{
JFrame frame = new JFrame(title(applet));
setupClosing(frame);
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));
setupClosing(frame);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}
///
import javax.swing.*;
import java.awt.event.*;
public class Console
{
//get the title string from the class name
public static String title(Object o)
{
String t = o.getClass().toString();
if(t.indexOf("class") != -1)
t = t.substring(6);
return t;
}
public static void setupClosing(JFrame frame)
{
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void run(JFrame frame, int width, int height)
{
setupClosing(frame);
frame.setSize(width,height);
frame.setVisible(true);
}
public static void run(JApplet applet, int width, int height)
{
JFrame frame = new JFrame(title(applet));
setupClosing(frame);
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));
setupClosing(frame);
frame.getContentPane().add(panel);
frame.setSize(width,height);
frame.setVisible(true);
}
}
|
import java.applet.Applet;
import java.awt.Event;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.*;
public class StarterCombined extends Applet {
private Label label;
public static void main(String args[]) {
StarterCombinedFrame app =
new StarterCombinedFrame("Starter Application");
app.setSize(300,100);
app.show ();
System.out.println("StarterCombinedFrame::main()");
}
public void init() {
System.out.println("Applet::init()");
}
public void start() {
System.out.println("Applet::start()");
label = new Label("Starter");
add(label);
}
public void stop() {
System.out.println("Applet::stop()");
remove(label);
}
public void destroy() {
System.out.println("Applet::destroy()");
}
}
class StarterCombinedFrame extends Frame {
public StarterCombinedFrame(String frameTitle) {
super(frameTitle);
StarterCombined applet = new StarterCombined();
applet.start();
add (applet, "Center");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
dispose();
System.exit(0);
}
});
}
}
import java.awt.Event;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.*;
public class StarterCombined extends Applet {
private Label label;
public static void main(String args[]) {
StarterCombinedFrame app =
new StarterCombinedFrame("Starter Application");
app.setSize(300,100);
app.show ();
System.out.println("StarterCombinedFrame::main()");
}
public void init() {
System.out.println("Applet::init()");
}
public void start() {
System.out.println("Applet::start()");
label = new Label("Starter");
add(label);
}
public void stop() {
System.out.println("Applet::stop()");
remove(label);
}
public void destroy() {
System.out.println("Applet::destroy()");
}
}
class StarterCombinedFrame extends Frame {
public StarterCombinedFrame(String frameTitle) {
super(frameTitle);
StarterCombined applet = new StarterCombined();
applet.start();
add (applet, "Center");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
dispose();
System.exit(0);
}
});
}
}
|
其实很容易的,你直接在applet中加个main入口!
然后把applet当作一个Swing或awt控件用就行了!
如:
public static void main(String[] str){
JFrame jframe = new JFrame("dfd");
MyApplet app = new MyApplet();
app.init(); //一定要init()
app.setSize(200,200);
jframe.setBounds(100,200,500,300);
Container con = jframe.getContentPane();
con.setLayout(new BorderLayout());
jframe.getContentPane().add(app);
jframe.show();
}
然后把applet当作一个Swing或awt控件用就行了!
如:
public static void main(String[] str){
JFrame jframe = new JFrame("dfd");
MyApplet app = new MyApplet();
app.init(); //一定要init()
app.setSize(200,200);
jframe.setBounds(100,200,500,300);
Container con = jframe.getContentPane();
con.setLayout(new BorderLayout());
jframe.getContentPane().add(app);
jframe.show();
}
|
lianyunzxp@sina.com
俺试试
俺试试
|
change
extend Japplet to Jframe
extend Japplet to Jframe
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。