2012-11-06 57 views
-1

我使用Applet添加到html。 但图片没有执行。 没有错误信息。 出了什么问题? 我使用appletviewer来测试。 就像没有。Applet未启动

HTMLCODE

<body> 
<applet code=SS.class 
     archive="av.jar, httpclient-4.2.2.jar, httpcore-4.2.2.jar, commons-logging-1.1.1.jar, fluent-hc-4.2.2 httpclient-cache-4.2.2, httpmime-4.2.2" 
    width=719 height=679> 
</applet> 
</body> 
</html> 

我的代码非常混乱 于是我就打开他的框架 我类似的框架不应该正常运行

Java代码

import org.apache.http.HttpResponse; 
import org.apache.http.NameValuePair; 
import org.apache.http.ParseException; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.entity.UrlEncodedFormEntity; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.message.BasicNameValuePair; 
import org.apache.http.protocol.HTTP; 
import org.apache.http.util.EntityUtils; 

import java.applet.Applet; 
import java.awt.*; 
import java.awt.event.*; 
import java.io.IOException; 
import java.io.UnsupportedEncodingException; 
import java.util.ArrayList; 
import java.util.List; 
public class SS extends Applet 
{ 
    /** 
    * 
    */ 
    public static final long serialVersionUID = 1L; 

    public static void main(String args[]) 
    { 
    win1 bb = new win1(); 
    } 
} 


class win1 extends JFrame implements ActionListener 
{ 

    JButton bt2 = new JButton("1"); 
    JButton bt3 = new JButton("2"); 
    JButton bt4 = new JButton("3"); 
    JButton bt5 = new JButton("4"); 
    JButton bt6 = new JButton("5"); 
    JButton bt = new JButton("6"); 
    JButton bt7 = new JButton("7"); 
    JButton bt8 = new JButton("8"); 
    JButton bt9 = new JButton("9"); 
    JButton bt10 = new JButton("10"); 
    JButton sd = new JButton("11"); 
    JRadioButton jb1=new JRadioButton("12",true); 


    private JLabel Jlb_ID = new JLabel("13"); 
    private JLabel Jlb_PW = new JLabel("14"); 
    private JLabel txAC = new JLabel("15"); 
    private JLabel txPW = new JLabel("16"); 
    private JLabel Jlb_IP = new JLabel("IP"); 
    private JTextField jpw = new JTextField(10); 
    private JTextField UN = new JTextField(4); 
    private JTextField TM = new JTextField(2); 
    private JTextField F4 = new JTextField(1); 
    private JTextField kg = new JTextField(6); 
    private JTextField jid = new JTextField(10); 
    private JTextField name = new JTextField(10); 
    private JTextField pass= new JTextField(10); 
    private JTextField ip= new JTextField(10); 

    public win1() 
    { 
     super("win"); 
     setSize(100,800); 
     setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
     setVisible(true); 



      Container pn = getContentPane(); 
      FlowLayout fy = new FlowLayout(); 
      pn.setLayout(fy); 
      bt2.addActionListener(this); 
      bt3.addActionListener(this); 
      bt.addActionListener(this); 
      bt4.addActionListener(this); 
      bt5.addActionListener(this); 
      bt6.addActionListener(this); 
      bt7.addActionListener(this); 
      bt8.addActionListener(this); 
      bt9.addActionListener(this); 
      bt10.addActionListener(this); 
      sd.addActionListener(this); 
      jb1.addActionListener(this); 
      pn.add(Jlb_IP); 
      pn.add(ip); 
      pn.add(txAC); 
      pn.add(pass); 
      pn.add(txPW); 
      pn.add(name); 
      pn.add(bt2); 
      pn.add(Jlb_ID); 
      pn.add(jid); 
      pn.add(Jlb_PW); 
      pn.add(jpw); 
      pn.add(bt); 
      pn.add(UN); 
      pn.add(bt7); 
      pn.add(bt8); 
      pn.add(TM); 
      pn.add(bt9); 
      pn.add(bt3); 
      pn.add(bt4); 
      pn.add(bt5); 
      pn.add(bt6); 
      pn.add(F4); 
      pn.add(bt10); 
      pn.add(kg); 
      pn.add(sd); 
      pn.add(jb1); 


      Jlb_PW.setLocation(250,50); 
      Jlb_PW.setSize(100,20); 
      Jlb_PW.setFont(new Font("Serif",Font.BOLD,16)); 
      txPW.setLocation(250,50); 
      txPW.setSize(100,20); 
      txPW.setFont(new Font("Serif",Font.BOLD,16)); 
      bt2.setLocation(250,50); 
      bt2.setSize(100,20); 
      txPW.setFont(new Font("Serif",Font.BOLD,16)); 
      txAC.setLocation(250,50); 
      txAC.setSize(100,20); 
      txAC.setFont(new Font("Serif",Font.BOLD,16)); 
      Jlb_ID.setLocation(100,200); 
      Jlb_ID.setSize(100,20); 
      Jlb_ID.setFont(new Font("Serif",Font.BOLD,16)); 
      jpw.setLocation(70,50); 
      jpw.setSize(100,20); 
      jpw.setToolTipText("KKKKK"); 
      jid.setLocation(10,50); 
      jid.setSize(100,20); 
      jid.setToolTipText("KKKKKK"); 
      name.setLocation(10,150); 
      name.setSize(100,20); 
      pass.setLocation(10,200); 
      pass.setSize(100,20); 
      ip.setLocation(10,250); 
      ip.setSize(100,20); 

      setContentPane(pn); 

    } 

    @Override 
    public void actionPerformed(ActionEvent arg0) { 
     // TODO Auto-generated method stub 

    } 



    } 
+1

1)的基础知识,不要做任何'的setSize(..)'或'setLocation(..)'的。请使用布局,填充和边框来布局GUI。 2)在“SS”类中的代码量之前,你应该早已测试过它。编译/经常运行! –

回答

2

我认为宁可在public class SS extends Applet中创建主体,您必须创建init()方法。

public class SS extends Applet 
{ 
    /** 
    * 
    */ 
    public void init() { 
    win1 bb = new win1(); 
    getContentPane().add(bb) 
    } 
} 

但首先,你必须要经过小程序How to Make Applets

+0

+1为一个很好的答案,但特别喜欢的位开始*“但是第一次..”*。 –

+0

;)谢谢@AndrewThompson –

+0

我最初认为只要继承像 原文写这么多东西需要更改 非常感谢 –