J'ai quelques problèmes.
1. Je veux afficher un message avant de quitter. Cliquez sur le bouton et afficher le message et après 0,5 seconde quitter le programme et ouvrir le programme suivant.
2. Je veux changer de couleur; dans la première couleur de l'application est correcte, mais dans la couleur suivante est par défaut.
Pouvez-vous modifier ceci ou dit pas à pas comment faire ceci? Merci pour toute aide :).
Code de premier programme:JLabel ne pas afficher
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.TimeUnit;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Start extends JFrame implements ActionListener
{
JButton Polski, English; //nazwy przycisków
JLabel jezyk, language;
static JLabel wybór;
public Start()
{
setSize(330,170);//rozmiar
setTitle("MathCalc v0.1 by Majkel");
setLayout(null);
jezyk = new JLabel("Choose language:");
jezyk.setBounds(40,10,200,40);
add(jezyk);
Polski = new JButton("Polski");
Polski.setBounds(40,50,100,30);
add(Polski);
Polski.addActionListener(this);
English = new JButton("English");
English.setBounds(150,50,100,30);
add(English);
English.addActionListener(this);
wybór = new JLabel("Choose");
wybór.setBounds(40,90,400,30);
add(wybór);
}
public static void main(String[] args)
{
System.out.println("Choose language:");
Start okno1 = new Start();
okno1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
okno1.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e)
{
Object klik = e.getSource();
if(klik==Polski)
{
wybór.setText("Wybrałeś język Polski.".toString()); //I want to show this massage before exit, but it not show
System.out.println("Wybrałeś język Polski."); //This show corect in console
try {
Thread.sleep(100);
this.setVisible(false);
new czynnośćPL().setVisible(true);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
else if(klik==English)
{
wybór.setText("You have chosen English.".toString()); //I want to show this massage before exit, but it not show
System.out.println("You have chosen English."); //This show corect in console
try {
Thread.sleep(100);
this.setVisible(false);
new czynnośćPL().setVisible(true);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
Et deuxième programme:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class czynnośćPL extends JFrame implements ActionListener
{
JButton pole, obwód, objętość; //nazwy przycisków
JLabel Wybór, oblicz;
public czynnośćPL()
{
setSize(400,200);//rozmiar
setTitle("MathCalc v0.1 by Majkel");
setLayout(null);
setBackground(Color.blue);
oblicz = new JLabel("Oblicz:");
oblicz.setBounds(40,10,200,40);
add(oblicz);
pole = new JButton("pole");
pole.setBounds(40,50,100,30);
add(pole);
pole.addActionListener(this);
obwód = new JButton("obwód");
obwód.setBounds(150,50,100,30);
add(obwód);
obwód.addActionListener(this);
objętość = new JButton("objętość");
objętość.setBounds(260,50,100,30);
add(objętość);
objętość.addActionListener(this);
}
public static void main(String[] args)
{
Start okno1 = new Start();
okno1.getContentPane().setBackground(new Color(189,189,189));
okno1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
okno1.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e)
{
Object klik = e.getSource();
if(klik==pole)
{
System.out.println("Wybrałeś pole.");
try {
Thread.sleep(100);
this.setVisible(false);
new polePL().setVisible(true);//co ma open
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
else if(klik==obwód)
{
System.out.println("Wybrałeś obwód.");
try {
Thread.sleep(100);
this.setVisible(false);
new czynnośćPL().setVisible(true);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
else if(klik==objętość)
{
System.out.println("Wybrałeś objętość.");
try {
Thread.sleep(100);
this.setVisible(false);
new czynnośćPL().setVisible(true);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
Désolé, ce n'est pas un service de codage. Vous devez fournir des efforts et nous montrer ce que vous avez essayé – CraigR8806
Bienvenue dans Stack Overflow! S'il vous plaît prenez le [tour] (http://stackoverflow.com/tour), jetez un coup d'œil autour, et lisez le [centre d'aide] (http://stackoverflow.com/help), en particulier [Comment puis-je demander une bonne question?] (http://stackoverflow.com/help/how-to-ask) et [Quels sujets puis-je poser à propos d'ici?] (http://stackoverflow.com/help/on-topic). - veuillez respecter les [Conventions de nommage Java] (http://www.oracle.com/technetwork/java/codeconventions-135099.html). Veuillez également traduire votre code en anglais. –
essayez d'appeler revalidate() après avoir défini la nouvelle valeur de JLabel –