bestehende Applikation auch als Applet lauffähig zu machen

Status
Nicht offen für weitere Antworten.

Froop

Mitglied
Hi Zusammen,

ich habe eine recht umfangreiche GUI als Applikation erstellt und möchte diese nun auch wahlweise als Applet starten können.
Von L-ectron-X habe ich das Beispiel zu einer Appletcation gelesen. Dort gibt es nun eine Frame und eine Applet Klasse. Meine bestehende JFrame Klasse steuert nun den Zugriff auf sehr viele Dialoge, die auch wiederum Zugriff aus diese Klasse haben.
Gibt es denn eine elegante Lösung um in einer Startklasse beide Varianten zu implementieren?

Web Start ist für mich nicht die Alternative zum Applet, da ich Web Start auch noch parallel unterstützen möchte.

Danke schon einmal,
Froop
 

Angel4585

Bekanntes Mitglied
Ich mach das immer so:

Ich hab ein JPanel wo meine "Startmaske" drauf ist.
Dieses StartPanel kann ich dann in NetBeans auf ein JApplet und auf ein JFrame schieben. So hab ich eine Anwendung ganz schnell als Applet und "normal"
 

Froop

Mitglied
Da scheint NetBeans vieles automatisch zu machen. Ich verwende Eclipse. Kannst du mir die Klasse mal zeigen?

Danke Froop
 

Angel4585

Bekanntes Mitglied
Hab mal drei neue Klasen erstellt weil ich mein Projekt nicht hier hab:

Das Panel:
Code:
/*
 * StartPanel.java
 *
 * Created on 29. Januar 2008, 14:22
 */

package cs_test;

/**
 *
 * @author  M.Weber
 */
public class StartPanel extends javax.swing.JPanel {
    
    /** Creates new form StartPanel */
    public StartPanel() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>
    
    
    // Variables declaration - do not modify
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration
    
}

Frame mit Panel:
Code:
/*
 * StartFrame.java
 *
 * Created on 29. Januar 2008, 14:22
 */

package cs_test;

/**
 *
 * @author  M.Weber
 */
public class StartFrame extends javax.swing.JFrame {
    
    /** Creates new form StartFrame */
    public StartFrame() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        startPanel1 = new cs_test.StartPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(startPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(startPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new StartFrame().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify
    private cs_test.StartPanel startPanel1;
    // End of variables declaration
    
}

Das Applet mit Panel drauf:
Code:
/*
 * StartApplet.java
 *
 * Created on 29. Januar 2008, 14:22
 */

package cs_test;

/**
 *
 * @author  M.Weber
 */
public class StartApplet extends javax.swing.JApplet {
    
    /** Initializes the applet StartApplet */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        startPanel1 = new cs_test.StartPanel();

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(startPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(startPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
        );
    }// </editor-fold>
    
    
    // Variables declaration - do not modify
    private cs_test.StartPanel startPanel1;
    // End of variables declaration
    
}
 

Froop

Mitglied
Danke für deine Antwort Angel4585, leider ist es nicht ganz das was ich gesucht habe. Ich möchte gerne beide Varianten (Applet und Applikation) in einer Klasse integriert haben.
Wenn jemand weiß, dass es so nicht geht, wäre das auch schon hilfreich.
 

Angel4585

Bekanntes Mitglied
schonmal versucht ein JApplet anzulegen und diesem einfach ne main() Methode zu geben?

EDIT: War glaub ne Schnapsidee, das geht nich :lol:
 

Froop

Mitglied
Da bin ich gerade dabei.
Das Applet wird schon angezeigt nur bei der Applikation wird noch nichts angezeigt und es kommt keine Fehlermeldung. Ich bereite noch etwas Code vor, den stelle ich dann rein.
 

Froop

Mitglied
Ich habe jetzt eine Lösung gefunden für eine Appletcation in einer Klasse. Ich kann das Progrämmchen als Applet und Applikation starten.
Bisher sehe ich kein größeres Problem, welches dadurch auftreten könnte.

Hier das Beispiel:
Code:
import java.awt.BorderLayout;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JFrame;

//
//public class Test extends JFrame
public class Test extends JApplet
{
    static 	Test 	test;
    static	JFrame 	frame;
    
	private static final long serialVersionUID = 1L;

	private static JPanel jContentPane 	= null;

	
    public void init()
    {
        System.out.println ("Init()");
        
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
    }
    public void start()
    {
        System.out.println ("Start()");
    }
    public void stop ()
    {
       System.out.println ("Stop()");
    }
    public void destroy ()
    {
       System.out.println ("Destroy()");
    }
	
    
	private void init_application()
	{
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
		frame.setTitle("JFrame: Application");
	}

	private static JPanel getJContentPane() 
	{
		if (jContentPane == null) 
		{
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
		}
		return jContentPane;
	}

	
	public static void main(String[] args) 
	{
	      frame	= new JFrame("Application");

	      test 	= new Test();


	      test.init_application();

	      frame.setSize (300, 200);
	      frame.setVisible (true);

	}
}
[/list]
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
M Bereits bestehende Applet-Objects nutzen Tools - Maven, Gradle, Ant & mehr 3
T Java Applikation an Clients verteilen Tools - Maven, Gradle, Ant & mehr 5
S Webstart Webstart einer Applikation mit einer veralteten JNLP-Datei Tools - Maven, Gradle, Ant & mehr 6
T Applikation mit VM verpacken? Tools - Maven, Gradle, Ant & mehr 10
S Java Applikation als Windows Service einrichten Tools - Maven, Gradle, Ant & mehr 23
P Java Applikation auf Server Tools - Maven, Gradle, Ant & mehr 7
F Applikation (nicht Applet) im Browser starten Tools - Maven, Gradle, Ant & mehr 9
G JApplet parallel zu Java-Applikation entwickeln Tools - Maven, Gradle, Ant & mehr 11
M Brauche Unterstützung bei Chat Applikation Tools - Maven, Gradle, Ant & mehr 1
J Ausführung verhindern Applikation entführt wurde möglich ? Tools - Maven, Gradle, Ant & mehr 3
J Code rennt als Applikation aber nicht als Applet? Tools - Maven, Gradle, Ant & mehr 3
J [JWS] Applikation per Shell-Aufruf mit Parametern Tools - Maven, Gradle, Ant & mehr 2
G Webstart Applikation als Applet in JSP Seite? Tools - Maven, Gradle, Ant & mehr 8
L Applikation Verarb (Server) - Applet als Darstell (Client) Tools - Maven, Gradle, Ant & mehr 5
N Applikation als Applet Tools - Maven, Gradle, Ant & mehr 3
M Applikation --> Applet Tools - Maven, Gradle, Ant & mehr 4
T Inhalt (=ehem. Applikation) in Applet unsichtbar Tools - Maven, Gradle, Ant & mehr 5
B Eine Applikation in ein Applet umwandeln Tools - Maven, Gradle, Ant & mehr 4
A Applikation vs. Applet Tools - Maven, Gradle, Ant & mehr 3
M jpackage zusätzlich zu deb installer auch einen windows installer bauen Tools - Maven, Gradle, Ant & mehr 9
Y applet löscht den hintergrund auch mit doppelpufferung Tools - Maven, Gradle, Ant & mehr 3
G Gibts auch so was wie StringToInt? Tools - Maven, Gradle, Ant & mehr 5

Ähnliche Java Themen


Oben