将J帧转换为JApplet

时间:2016-04-29 00:30:43

标签: java swing applet jframe japplet

我创建了一个java代码(jframe),但我正在尝试将其转换为applet,以便它可以出现在html网页上。转换困难,因为我不太熟悉java编码。

以下是目前的代码:

Z

这是原始的Jframe代码

 /**
  * Implements a program with a pie chart
 * that shows interactive polling results for three candidates
 */

  import java.awt.*;
  import javax.swing.*;

  public class Poll extends JApplet {

         public void init() {
 public Poll()
   {

 super("Vote for Pat, Ismail, or Clair");
Container c = getContentPane();
c.setBackground(Color.WHITE);
PollDisplayPanel chart = new PollDisplayPanel("Pat", "Ismail", "Clair");
PollControlPanel controls = new PollControlPanel(chart);
c.add(chart, BorderLayout.CENTER);
c.add(controls, BorderLayout.SOUTH);

Poll w = new Poll();
}



        }
        }

1 个答案:

答案 0 :(得分:1)

您无法直接在另一个内部定义方法。在这里你已经为applet做了同样的事情。在init()内,您要添加构造函数Poll()

 public void init() {

<击>

<击>
    public Poll() {
    super("Vote for Pat, Ismail, or Clair");

<击>

    Container c = getContentPane();
    c.setBackground(Color.WHITE);
    PollDisplayPanel chart = new PollDisplayPanel("Pat", "Ismail", "Clair");
    PollControlPanel controls = new PollControlPanel(chart);
    c.add(chart, BorderLayout.CENTER);
    c.add(controls, BorderLayout.SOUTH);

<击>

<击>
      Poll w = new Poll();
    }

<击>

 }