将JFrame转换为JApplet

时间:2015-02-11 14:15:45

标签: java swing applet jframe japplet

我想在applet中转换扩展JFrame的项目,以便在网页上运行它。有人可以帮助我并告诉我如何做到这一点吗?

在这里发布项目的片段代码:

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;

import CLIPSJNI.Environment;
import CLIPSJNI.PrimitiveValue;

import javax.swing.JTextPane;

import java.awt.Font;
import java.awt.event.MouseEvent;
import java.util.StringTokenizer;
import java.awt.Color;

import javax.swing.SwingConstants;
import javax.swing.JScrollPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Progetto extends JFrame {

static Object ProfileData[] = new Object[30];

static Environment clips=new Environment();

static PrimitiveValue rv; 
static String a="?*send*";

private JPanel contentPane;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                clips.load("prova.clp");

                clips.reset();
                clips.run();
                Progetto frame = new Progetto();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 * @throws Exception 
 */
public Progetto() throws Exception  {
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 30, 662, 671);
    contentPane = new JPanel();
    contentPane.setBackground(Color.LIGHT_GRAY);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    rv=clips.eval(a);
    ProfileData=(Object[]) Progetto.codificaCodice(rv.stringValue());
    System.out.println((String) Progetto.ProfileData[0]);

    JLabel lblTravel = new JLabel("Travel Recommender");
    lblTravel.setForeground(new Color(204, 0, 0));
    lblTravel.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 30));
    lblTravel.setHorizontalAlignment(SwingConstants.CENTER);
    lblTravel.setBounds(-29, 11, 636, 49);
    contentPane.add(lblTravel);

    JButton range1 = new JButton("0 - 18");
    range1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        }
    });
    range1.setForeground(Color.BLACK);
    range1.setFont(new Font("Trebuchet MS", Font.PLAIN, 15));
    range1.setBackground(Color.CYAN);
    range1.setBounds(176, 221, 89, 31);
    contentPane.add(range1);

    JTextPane txtpnFsd = new JTextPane();
    txtpnFsd.setToolTipText("");
    contentPane.add(txtpnFsd);

    txtpnFsd.setForeground(Color.BLACK);
    txtpnFsd.setBackground(Color.LIGHT_GRAY);
    txtpnFsd.setFont(new Font("Trebuchet MS", Font.BOLD | Font.ITALIC, 15));

    txtpnFsd.setEditable(false);
    txtpnFsd.setBounds(213, 134, 139, 76);
    txtpnFsd.setText((String) ProfileData[0]);


    range1.addMouseListener(new java.awt.event.MouseAdapter(){
        public void mouseClicked(MouseEvent e){
            Progetto.clips.eval((String) Progetto.ProfileData[1]);  //assert 0-18
            Progetto.clips.run();
            Progetto.rv=Progetto.clips.eval(a);
            try {
                Progetto.ProfileData=(Object[]) Progetto.codificaCodice(Progetto.rv.stringValue());
                System.out.println((String) Progetto.ProfileData[0]);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            Lavoro frame = null;
            try {
                frame= new Lavoro();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            frame.setVisible(true);
            dispose();
        }
    });

...

public static Object codificaCodice(String message) {

    Object token = null;
    int count = 0;
    Object ProfileData[] = new Object[30];
    for(StringTokenizer st = new StringTokenizer(message, "%"); st.hasMoreTokens(); count++)
    {
        token = st.nextToken();

        ProfileData[count] = (String) token;
        }
    return ProfileData;

    }
}   

0 个答案:

没有答案