Passer d'une fenetre a une autre.
JTownxxx232
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
alcode_fr Messages postés 12 Date d'inscription Statut Membre Dernière intervention -
alcode_fr Messages postés 12 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je suis débutant en java et j'aimerai recevoir de l'aide de personne plus agéris.
Je suis en cours de création d'un launcher pour un serveur Minecraft. Sur celui-ci j'aimerais qu'il y ai plusieurs onglets. J'aimerais qu’à partir d'un JButton je puisse accéder à une autre page. Mais je n'arrive pas à faire en sorte que quand j'appuie sur le bouton (par exemple boutique) le JPanel boutique s'ouvre. Sur celui-ci je voudrais applique une image de fond et y placer des boutons.
Ne supprimer rien au code sinon, le reste ne marchera plus.
Voici le code de ma classe LauncherPanel
Merci d'avance.
**Modifié par la modération pour une lecture plus facile du code, à l'avenir utilisez les balises, VOIR CETTE PAGE
Je suis débutant en java et j'aimerai recevoir de l'aide de personne plus agéris.
Je suis en cours de création d'un launcher pour un serveur Minecraft. Sur celui-ci j'aimerais qu'il y ai plusieurs onglets. J'aimerais qu’à partir d'un JButton je puisse accéder à une autre page. Mais je n'arrive pas à faire en sorte que quand j'appuie sur le bouton (par exemple boutique) le JPanel boutique s'ouvre. Sur celui-ci je voudrais applique une image de fond et y placer des boutons.
Ne supprimer rien au code sinon, le reste ne marchera plus.
Voici le code de ma classe LauncherPanel
package fr.Jtownxxx232.solidira.launcher; import java.awt.Color; import java.awt.Container; import java.awt.Frame; import java.awt.Graphics; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; import fr.theshark34.openauth.AuthenticationException; import fr.theshark34.openlauncherlib.launcher.util.UsernameSaver; import fr.theshark34.swinger.Swinger; import fr.theshark34.swinger.colored.SColoredBar; import fr.theshark34.swinger.event.SwingerEvent; import fr.theshark34.swinger.event.SwingerEventListener; import fr.theshark34.swinger.textured.STexturedButton; import fr.theshark34.swinger.util.WindowMover; @SuppressWarnings("serial") public class LauncherPanel extends JPanel implements SwingerEventListener { private static final SwingerEventListener ActionListener = null; private static final String ButtonMouseClicked = null; private Image background = Swinger.getResource("background.png"); private UsernameSaver saver = new UsernameSaver(Launcher.SD_INFOS); private JTextField usernameField = new JTextField(saver.getUsername("")); private JPasswordField passwordField = new JPasswordField(); private STexturedButton playButton = new STexturedButton(Swinger.getResource("playbutton.png")); private STexturedButton quitButton = new STexturedButton(Swinger.getResource("quitbutton.png")); private STexturedButton hideButton = new STexturedButton(Swinger.getResource("hidebutton.png")); private SColoredBar progressBar = new SColoredBar(new Color(255, 255, 255)); private JLabel infoLabel = new JLabel("Clique sur jouer !", SwingConstants.CENTER); JPanel panel1 = new JPanel(); public LauncherPanel() { this.setLayout(null); usernameField.setForeground(Color.WHITE); usernameField.setFont(usernameField.getFont().deriveFont(20F)); usernameField.setCaretColor(Color.WHITE); usernameField.setBorder(null); usernameField.setOpaque(false); usernameField.setBounds(69, 259, 355, 48); this.add(usernameField); passwordField.setForeground(Color.WHITE); passwordField.setFont(usernameField.getFont()); passwordField.setCaretColor(Color.WHITE); passwordField.setBorder(null); passwordField.setOpaque(false); passwordField.setBounds(69, 345, 355, 48); this.add(passwordField); playButton.setBounds(64, 420); playButton.addEventListener(this); this.add(playButton); quitButton.setBounds(977, 1); quitButton.addEventListener(this); this.add(quitButton); hideButton.setBounds(957, 11); hideButton.addEventListener(this); this.add(hideButton); progressBar.setBounds(0, 578, 1000, 28); this.add(progressBar); infoLabel.setBounds(0, 550, 1000, 28); infoLabel.setForeground(Color.WHITE); infoLabel.setFont(usernameField.getFont()); this.add(infoLabel); } @Override public void onEvent(SwingerEvent e) { if(e.getSource() == playButton) { setFieldsEnabled(false); if(usernameField.getText().replaceAll(" ", "").length() == 0 || passwordField.getText().length() == 0) { JOptionPane.showMessageDialog(this, "Erreur, veuillez entrer un mot de passe ou un pseudo valide", "Erreur", JOptionPane.ERROR_MESSAGE ); setFieldsEnabled(true); return; } Thread t = new Thread() { @Override public void run() { try { Launcher.auth(usernameField.getText(), passwordField.getText()); } catch (AuthenticationException e) { JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, impossible de se connecter : " + e.getErrorModel().getErrorMessage(), "Erreur", JOptionPane.ERROR_MESSAGE ); setFieldsEnabled(true); return; } try { Launcher.update(); } catch (Exception e) { Launcher.interruptThread(); JOptionPane.showMessageDialog(LauncherPanel.this, "Erreur, impossible de mettre le jeu à jour : " + e, "Erreur", JOptionPane.ERROR_MESSAGE ); setFieldsEnabled(true); return; } } }; t.start(); } else if(e.getSource() == quitButton) System.exit(0); else if(e.getSource() == hideButton) LauncherFrame.getInstance().setState(JFrame.ICONIFIED); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(background, 0, 0, this.getWidth(), this.getHeight(), this); } private void setFieldsEnabled(boolean enabled) { usernameField.setEnabled(enabled); passwordField.setEnabled(enabled); playButton.setEnabled(enabled); } public SColoredBar getProgressBar() { return progressBar; } public void setInfoText(String text) { infoLabel.setText(text); } } Le code de ma class : LauncherFrame package fr.Jtownxxx232.solidira.launcher; import javax.swing.JFrame; import fr.theshark34.swinger.Swinger; import fr.theshark34.swinger.util.WindowMover; @SuppressWarnings("serial") public class LauncherFrame extends JFrame { private static LauncherFrame instance; private LauncherPanel launcherPanel; public LauncherFrame() { this.setTitle("Solidira launcher 1.0"); this.setSize(1000, 650); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setIconImage(Swinger.getResource("icon.png")); this.setUndecorated(true); this.setContentPane(launcherPanel = new LauncherPanel()); WindowMover mover = new WindowMover(this); this.addMouseListener(mover); this.addMouseMotionListener(mover); this.setVisible(true); } public static void main(String[] args) { Swinger.setSystemLookNFeel(); Swinger.setResourcePath("/fr/Jtownxxx232/solidira/launcher/resources/"); instance = new LauncherFrame(); } public static LauncherFrame getInstance() { return instance; } public LauncherPanel getLauncherPanel() { return this.launcherPanel; } public void changerMenu() { // TODO Auto-generated method stub } }
Merci d'avance.
**Modifié par la modération pour une lecture plus facile du code, à l'avenir utilisez les balises, VOIR CETTE PAGE
A voir également:
- Passer d'une fenetre a une autre.
- Passer de qwerty a azerty - Guide
- Passer a windows 10 - Accueil - Mise à jour
- Fenetre windows - Guide
- Fenêtre hors écran windows 11 - Guide
- Passer de majuscule à minuscule - Guide