gpt4 book ai didi

java - 将 J 框架转换为 JApplet

转载 作者:行者123 更新时间:2023-12-01 09:59:28 25 4
gpt4 key购买 nike

我已经创建了一个java代码(jframe),但我正在尝试将其转换为小程序,以便它可以出现在html网页上。由于我不太熟悉 java 编码,因此转换遇到困难。

这是到目前为止的代码:

 /**
* 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();
}



}
}

这是原始的 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 JFrame
{
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);
}

public static void main(String[] args)
{
Poll w = new Poll();}
w.setBounds(300, 300, 400, 400);
w.setDefaultCloseOperation(EXIT_ON_CLOSE);
w.setVisible(true);
}
}

最佳答案

您不能直接在另一个方法中定义方法。在这里,您已对小程序执行了相同的操作。里面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();
}

<罢工>

 }

关于java - 将 J 框架转换为 JApplet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36927623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com