Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
4145 connectés 

 


Dernière réponse
Sujet : comment transformer un applet java en programme a par entiere ?
WiseTechi Salut perso, j'utilise une petite classe qui sert de "launcher" universel pour tout ce qui est Applet, JApplet, JFrame, etc...
 
Donc, dans ta classe qui dérive d'Applet, tu rajoutes la méthode

public static void main(String[] args) {
  Console.run(new NOM_DE_TA_CLASSE(), 500, 300) ;
}

 
et ensuite tu définis la classe console comme ça :

import javax.swing.* ;
import java.awt.event.* ;
import java.applet.* ;
 
public class Console {
 // Create a title string from the class name:
 public static String title(Object o) {
  String t = o.getClass().toString() ;
  // Remove the word "class":
  if(t.indexOf("class" ) != -1)
   t = t.substring(6) ;
  return t ;
 }
 
 public static void setupClosing(JFrame frame) {
  // The JDK 1.2 Solution as an
  // anonymous inner class:
  frame.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e) {
    System.exit(0) ;
   }
  }) ;
  // The improved solution in JDK 1.3:
  // frame.setDefaultCloseOperation(
  // EXIT_ON_CLOSE) ;
 }
 
 public static void run(JFrame frame, int width, int height) {
  System.out.println("Starting Console" ) ;
  setupClosing(frame) ;
  frame.setSize(width, height) ;
  frame.setVisible(true) ;
 }
 public static void run(JApplet applet, int width, int height) {
  System.out.println("Starting Console" ) ;
  JFrame frame = new JFrame(title(applet)) ;
  setupClosing(frame) ;
  frame.getContentPane().add(applet) ;
  frame.setSize(width, height) ;
  applet.init() ;
  applet.start() ;
  frame.setVisible(true) ;
 }
 public static void run(Applet applet, int width, int height) {
  System.out.println("Starting Console" ) ;
  JFrame frame = new JFrame(title(applet)) ;
  setupClosing(frame) ;
  frame.getContentPane().add(applet) ;
  frame.setSize(width, height) ;
  applet.init() ;
  applet.start() ;
  frame.setVisible(true) ;
 }
 public static void run(JPanel panel, int width, int height) {
  System.out.println("Starting Console" ) ;
  JFrame frame = new JFrame(title(panel)) ;
  setupClosing(frame) ;
  frame.getContentPane().add(panel) ;
  frame.setSize(width, height) ;
  frame.setVisible(true) ;
 }
}

Les connaisseurs, auront bien sûr remarqué la provenance de cette classe de l'excellent Thinking in Java
 
A++

 

[edit]--Message édité par Wisetechi--[/edit]


Votre réponse
Nom d'utilisateur    Pour poster, vous devez être inscrit sur ce forum .... si ce n'est pas le cas, cliquez ici !
Le ton de votre message                        
                       
Votre réponse


[b][i][u][strike][spoiler][fixed][cpp][url][email][img][*]   
 
   [quote]
 

Options

 
Vous avez perdu votre mot de passe ?


Vue Rapide de la discussion
WiseTechi Salut perso, j'utilise une petite classe qui sert de "launcher" universel pour tout ce qui est Applet, JApplet, JFrame, etc...
 
Donc, dans ta classe qui dérive d'Applet, tu rajoutes la méthode

public static void main(String[] args) {
  Console.run(new NOM_DE_TA_CLASSE(), 500, 300) ;
}

 
et ensuite tu définis la classe console comme ça :

import javax.swing.* ;
import java.awt.event.* ;
import java.applet.* ;
 
public class Console {
 // Create a title string from the class name:
 public static String title(Object o) {
  String t = o.getClass().toString() ;
  // Remove the word "class":
  if(t.indexOf("class" ) != -1)
   t = t.substring(6) ;
  return t ;
 }
 
 public static void setupClosing(JFrame frame) {
  // The JDK 1.2 Solution as an
  // anonymous inner class:
  frame.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e) {
    System.exit(0) ;
   }
  }) ;
  // The improved solution in JDK 1.3:
  // frame.setDefaultCloseOperation(
  // EXIT_ON_CLOSE) ;
 }
 
 public static void run(JFrame frame, int width, int height) {
  System.out.println("Starting Console" ) ;
  setupClosing(frame) ;
  frame.setSize(width, height) ;
  frame.setVisible(true) ;
 }
 public static void run(JApplet applet, int width, int height) {
  System.out.println("Starting Console" ) ;
  JFrame frame = new JFrame(title(applet)) ;
  setupClosing(frame) ;
  frame.getContentPane().add(applet) ;
  frame.setSize(width, height) ;
  applet.init() ;
  applet.start() ;
  frame.setVisible(true) ;
 }
 public static void run(Applet applet, int width, int height) {
  System.out.println("Starting Console" ) ;
  JFrame frame = new JFrame(title(applet)) ;
  setupClosing(frame) ;
  frame.getContentPane().add(applet) ;
  frame.setSize(width, height) ;
  applet.init() ;
  applet.start() ;
  frame.setVisible(true) ;
 }
 public static void run(JPanel panel, int width, int height) {
  System.out.println("Starting Console" ) ;
  JFrame frame = new JFrame(title(panel)) ;
  setupClosing(frame) ;
  frame.getContentPane().add(panel) ;
  frame.setSize(width, height) ;
  frame.setVisible(true) ;
 }
}

Les connaisseurs, auront bien sûr remarqué la provenance de cette classe de l'excellent Thinking in Java
 
A++

 

[edit]--Message édité par Wisetechi--[/edit]

athor et au nivo des librairie a inclures ??
zop

Athor a écrit a écrit :

:hello:  
 
tout est dans le titre  
 
si il existe un soft qui fait ca  
ou alors k'est ce qu'il fo modifier dans le code source pour le faire  
 
merci d'avance




 
Si tu as les sources, il faut implémenter une méthode main:
'public static void main(String args[])'
dans la classe qui lance l'application

athor :hello:  
 
tout est dans le titre  
 
si il existe un soft qui fait ca  
ou alors k'est ce qu'il fo modifier dans le code source pour le faire  
 
merci d'avance

Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)