私はいくつか問題があります。
1.終了する前にメッセージを表示したい。ボタンを押してメッセージを表示し、0.5秒後にプログラムを終了して次のプログラムを開きます。
2.色を変更したい。最初のアプリの色は正しいが、次の色はデフォルトです。
これを修正したり、手順をステップごとに教えてもらえますか?助けをありがとう:)。最初のプログラムの
コード:JLabelが表示されない
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();
}
}
}
}
そして、第2のプログラム:
Timer timer = new Timer(milliseconds, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
hideMessageDialog();
Start.this.setVisible(false);
new czynnośćPL().setVisible(true);
}
});
timer.setRepeats(false);
timer.start();
milliseconds
セット:あなたは特別な遅延の後、GUIスレッドでタスクを実行するためにjavax.swing.Timer
を使用する必要が
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();
}
}
}
}
。努力をして、試したことを示す必要があります – CraigR8806
ようこそ! [ツアー](http://stackoverflow.com/tour)を見て回り、[ヘルプセンター](http://stackoverflow.com/help)、特に[どのように私に質問しますか良い質問?](http://stackoverflow.com/help/how-to-ask)と[ここで私はどのような話題を聞くことができますか?](http://stackoverflow.com/help/on-topic)。 - [Java命名規則](http://www.oracle.com/technetwork/java/codeconventions-135099.html)を尊重してください。 また、コードを英語に翻訳してください。 –
JLabelの新しい値を設定した後にrevalidate()を呼び出してみてください –