当前位置: 技术问答>java相关
求助,applet在浏览器里面的显示问题
来源: 互联网 发布时间:2015-01-26
本文导语: 我编了一个applet,里面有很多组件,在appletviewer里面都能显示,可是,在浏览器里面却有些显示不出来,不知道如何解决?没有用到swing,IE5.0 | 按钮可见了! import java.awt.*; import java.applet.*; impor...
我编了一个applet,里面有很多组件,在appletviewer里面都能显示,可是,在浏览器里面却有些显示不出来,不知道如何解决?没有用到swing,IE5.0
|
按钮可见了!
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
public class IE extends Applet
{
TopPanel MainTopPanel;
MainWindow IEMainWindow;
TopButtonArea MainTopButtonArea;
private Color AppletBackColor;
public void init()
{
AppletBackColor=new Color(206,206,255);
// setSize(600,480);
setLayout(new BorderLayout());
setBackground(AppletBackColor);
TopPanel MainTopPanel=new TopPanel();
add("North",MainTopPanel);
IEMainWindow=new MainWindow();
IEMainWindow.setVisible(true);
// MainTopButtonArea=new TopButtonArea();
// MainTopButtonArea.setVisible(true);
// IEMainWindow.add("North",MainTopButtonArea);
}
public void destroy()
{
IEMainWindow.close();
}
}
class TopPanel extends Panel
{
private Label TitleLabel;
private Font TitleFont;
public TopPanel()
{
setLayout(new BorderLayout());
TitleFont=new Font("TimesRoman", Font.BOLD+Font.ITALIC, 20);
TitleLabel=new Label("Industry Engineering ALPHA1.0 Demo");
TitleLabel.setFont(TitleFont);
add("North",TitleLabel);
}
}
class MainWindow extends Frame
{
private MenuBar FileMenuBar;
private Menu ConnectMenu;
private Menu HelpMenu;
private Menu JavaZoneMenu;
private Menu IEMenu;
private Color BackgroundColor;
public MainWindow()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
setTitle("Demo Show");
BackgroundColor=new Color(149,149,255);
setLayout(new BorderLayout());
setBackground(BackgroundColor);
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
FileMenuBar=new MenuBar();
ConnectMenu=new Menu("Connect");
HelpMenu=new Menu("Help");
JavaZoneMenu=new Menu("JAVA Zone");
IEMenu=new Menu("Industry Engineering Zone");
MenuItem EditHostItem=new MenuItem("Edit Host");
MenuItem ConnectHostItem=new MenuItem("Connect Host");
MenuItem AboutIEItem=new MenuItem("About IE Software");
MenuItem AboutAuthorItem=new MenuItem("About Author");
MenuItem AccessGNUItem=new MenuItem("Access GNU");
MenuItem Java01=new MenuItem("java.sun.com");
ConnectMenu.add(EditHostItem);
ConnectMenu.addSeparator();
ConnectMenu.add(ConnectHostItem);
HelpMenu.add(AboutIEItem);
HelpMenu.addSeparator();
HelpMenu.add(AboutAuthorItem);
HelpMenu.addSeparator();
HelpMenu.add(AccessGNUItem);
JavaZoneMenu.add(Java01);
FileMenuBar.add(ConnectMenu);
FileMenuBar.add(JavaZoneMenu);
FileMenuBar.add(IEMenu);
FileMenuBar.add(HelpMenu);
FileMenuBar.setHelpMenu(HelpMenu);
setMenuBar(FileMenuBar);
TopButtonArea tba = new TopButtonArea();
add(tba,BorderLayout.CENTER);
setSize(640,480);
}
public void close(){
this.dispose();
this.setVisible(false);
}
}
class TopButtonArea extends Panel implements ActionListener
{
private Label IndexLabel;
private Font Font01;
private Color ButtonColor;
Block2D Block2DFrame;
public TopButtonArea()
{
ButtonColor=new Color(176,176,255);
Font01=new Font("TimesRoman", Font.BOLD, 16);
IndexLabel=new Label("Click The Left Button");
IndexLabel.setFont(Font01);
Button GantBT;
Button CookieBT;
Button Cookie3DBT;
Button BlockBT;
Button Block3DBT;
Button LineBT;
GantBT=new Button(" GANT ");
GantBT.addActionListener(this);
GantBT.setBackground(ButtonColor);
add(GantBT);
CookieBT=new Button(" Cookie ");
CookieBT.addActionListener(this);
CookieBT.setBackground(ButtonColor);
add(CookieBT);
Cookie3DBT=new Button("Cookie3D");
Cookie3DBT.addActionListener(this);
Cookie3DBT.setBackground(ButtonColor);
add(Cookie3DBT);
BlockBT=new Button(" Block ");
BlockBT.addActionListener(this);
BlockBT.setBackground(ButtonColor);
add(BlockBT);
Block3DBT=new Button(" Block3D ");
Block3DBT.addActionListener(this);
Block3DBT.setBackground(ButtonColor);
add(Block3DBT);
LineBT=new Button(" Line ");
LineBT.addActionListener(this);
LineBT.setBackground(ButtonColor);
add(LineBT);
add(IndexLabel);
}
public void actionPerformed (ActionEvent e)
{
String BLabel=e.getActionCommand();
if(BLabel.equals(" Block "))
{
Block2DFrame=new Block2D();
Block2DFrame.setTitle("Block2D");
Block2DFrame.setSize(480,320);
Block2DFrame.setVisible(true);
}
}
}
class Block2DCanvas extends Canvas
{
public Block2DCanvas()
{
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.draw3DRect(0, 0, 469, 319, true);
g.draw3DRect(3, 3, 463, 313, false);
}
}
class Block2D extends Frame
{
Color CanvasBackColor;
Block2DCanvas BlockCanvas;
public void Block2D(){
setLayout(new BorderLayout());
BlockCanvas=new Block2DCanvas();
CanvasBackColor=new Color(230,230,255);
BlockCanvas.setBackground(CanvasBackColor);
BlockCanvas.setSize(480,320);
this.add("Center",BlockCanvas);
BlockCanvas.setVisible(true);
}
}
MyAppwww Example1
MyAppwww
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
public class IE extends Applet
{
TopPanel MainTopPanel;
MainWindow IEMainWindow;
TopButtonArea MainTopButtonArea;
private Color AppletBackColor;
public void init()
{
AppletBackColor=new Color(206,206,255);
// setSize(600,480);
setLayout(new BorderLayout());
setBackground(AppletBackColor);
TopPanel MainTopPanel=new TopPanel();
add("North",MainTopPanel);
IEMainWindow=new MainWindow();
IEMainWindow.setVisible(true);
// MainTopButtonArea=new TopButtonArea();
// MainTopButtonArea.setVisible(true);
// IEMainWindow.add("North",MainTopButtonArea);
}
public void destroy()
{
IEMainWindow.close();
}
}
class TopPanel extends Panel
{
private Label TitleLabel;
private Font TitleFont;
public TopPanel()
{
setLayout(new BorderLayout());
TitleFont=new Font("TimesRoman", Font.BOLD+Font.ITALIC, 20);
TitleLabel=new Label("Industry Engineering ALPHA1.0 Demo");
TitleLabel.setFont(TitleFont);
add("North",TitleLabel);
}
}
class MainWindow extends Frame
{
private MenuBar FileMenuBar;
private Menu ConnectMenu;
private Menu HelpMenu;
private Menu JavaZoneMenu;
private Menu IEMenu;
private Color BackgroundColor;
public MainWindow()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
setTitle("Demo Show");
BackgroundColor=new Color(149,149,255);
setLayout(new BorderLayout());
setBackground(BackgroundColor);
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
FileMenuBar=new MenuBar();
ConnectMenu=new Menu("Connect");
HelpMenu=new Menu("Help");
JavaZoneMenu=new Menu("JAVA Zone");
IEMenu=new Menu("Industry Engineering Zone");
MenuItem EditHostItem=new MenuItem("Edit Host");
MenuItem ConnectHostItem=new MenuItem("Connect Host");
MenuItem AboutIEItem=new MenuItem("About IE Software");
MenuItem AboutAuthorItem=new MenuItem("About Author");
MenuItem AccessGNUItem=new MenuItem("Access GNU");
MenuItem Java01=new MenuItem("java.sun.com");
ConnectMenu.add(EditHostItem);
ConnectMenu.addSeparator();
ConnectMenu.add(ConnectHostItem);
HelpMenu.add(AboutIEItem);
HelpMenu.addSeparator();
HelpMenu.add(AboutAuthorItem);
HelpMenu.addSeparator();
HelpMenu.add(AccessGNUItem);
JavaZoneMenu.add(Java01);
FileMenuBar.add(ConnectMenu);
FileMenuBar.add(JavaZoneMenu);
FileMenuBar.add(IEMenu);
FileMenuBar.add(HelpMenu);
FileMenuBar.setHelpMenu(HelpMenu);
setMenuBar(FileMenuBar);
TopButtonArea tba = new TopButtonArea();
add(tba,BorderLayout.CENTER);
setSize(640,480);
}
public void close(){
this.dispose();
this.setVisible(false);
}
}
class TopButtonArea extends Panel implements ActionListener
{
private Label IndexLabel;
private Font Font01;
private Color ButtonColor;
Block2D Block2DFrame;
public TopButtonArea()
{
ButtonColor=new Color(176,176,255);
Font01=new Font("TimesRoman", Font.BOLD, 16);
IndexLabel=new Label("Click The Left Button");
IndexLabel.setFont(Font01);
Button GantBT;
Button CookieBT;
Button Cookie3DBT;
Button BlockBT;
Button Block3DBT;
Button LineBT;
GantBT=new Button(" GANT ");
GantBT.addActionListener(this);
GantBT.setBackground(ButtonColor);
add(GantBT);
CookieBT=new Button(" Cookie ");
CookieBT.addActionListener(this);
CookieBT.setBackground(ButtonColor);
add(CookieBT);
Cookie3DBT=new Button("Cookie3D");
Cookie3DBT.addActionListener(this);
Cookie3DBT.setBackground(ButtonColor);
add(Cookie3DBT);
BlockBT=new Button(" Block ");
BlockBT.addActionListener(this);
BlockBT.setBackground(ButtonColor);
add(BlockBT);
Block3DBT=new Button(" Block3D ");
Block3DBT.addActionListener(this);
Block3DBT.setBackground(ButtonColor);
add(Block3DBT);
LineBT=new Button(" Line ");
LineBT.addActionListener(this);
LineBT.setBackground(ButtonColor);
add(LineBT);
add(IndexLabel);
}
public void actionPerformed (ActionEvent e)
{
String BLabel=e.getActionCommand();
if(BLabel.equals(" Block "))
{
Block2DFrame=new Block2D();
Block2DFrame.setTitle("Block2D");
Block2DFrame.setSize(480,320);
Block2DFrame.setVisible(true);
}
}
}
class Block2DCanvas extends Canvas
{
public Block2DCanvas()
{
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.draw3DRect(0, 0, 469, 319, true);
g.draw3DRect(3, 3, 463, 313, false);
}
}
class Block2D extends Frame
{
Color CanvasBackColor;
Block2DCanvas BlockCanvas;
public void Block2D(){
setLayout(new BorderLayout());
BlockCanvas=new Block2DCanvas();
CanvasBackColor=new Color(230,230,255);
BlockCanvas.setBackground(CanvasBackColor);
BlockCanvas.setSize(480,320);
this.add("Center",BlockCanvas);
BlockCanvas.setVisible(true);
}
}
MyAppwww Example1
MyAppwww
|
这是安全机制的问题(如果程序没问题,能用appletviewer运行的话)
到sun.com下载HTMLCONVERTER把APPLET对应的HTML文件转换即可
急得给分哦!!
到sun.com下载HTMLCONVERTER把APPLET对应的HTML文件转换即可
急得给分哦!!
|
不是程序的问题,到sun的网站下一个新的plug_in
|
不是plug-in的问题,因为你没有什么swing组件,而且我用applet标签试了一下,也可以运行,且一切正常(在IE和appletviewer)都一样。
不知你那是什么情况?