Witam zdecydowalem sie zasiegnac waszej porady, poniewaz nie bardzo rozumiem w czym tkwi problem.
Program dziala w zasadzie bezblednie, problem wystepuje jedynie z JOptionPane.showMessageDialog(Exception).
Gdy otworze z JMenuBar opcje i okienko to pojawi sie JFrame. W tym wypadku, gdy wpisze cos nieprawidlowego to pojawi sie MessageDialog jeden raz.Ale jesli zamkne to okno dolnym przyciskiem (ten z ramka) to po przy ponownym uruchomieniu tego samego schematu(opcje okienko) i wpisaniu czegos blednego okienko informacyjne pojawia sie nie jeden ale juz dwa razy. Za trzecim razem juz trzy i tak dalej.
( 2. to akurat nie jest problem, poniewaz juz to robilem i dzialalo prawidlowo , w tym kodzie jednak
jakos nie zabardzo chce. Chodzi o JLabel ar = new JLabel(); w Klasie "Klasa2".
Poprzednio zastowowalem prozedure setEnable(treu/false), jesli nacisnelo sie przycisk
to obok JTextField wyskakiwala ikonka , gdy sie zamykalo okno prawym dolnym przyciskiem
to po ponownym uruchomieniu ikonka byla nadal widoczna, ale barwy miala przyciemnione.
Z ciekawosci zapytam czy jest mozliwe, aby ikonka calkowicie znikala (nie tylko tracila barwy)? )
Za wszelka pomoc wielkie dzieki!!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Klasa12 extends JFrame {
JFrame frame = new JFrame();
static JTextField tj = new JTextField();
static JTextField tj2 = new JTextField();
static JButton button = new JButton("L");
static Klasa2 x = new Klasa2();
public Klasa1(){
frame.setTitle("Window");
frame.setSize(600,500);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLayout(null);
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
frame.setLocation(size.width/2 - frame.getWidth()/2,size.height/2 - frame.getHeight()/2);
button.setBounds(40,370,100,60);
button.setBorder(BorderFactory.createRaisedBevelBorder());
frame.add(button);
tj.setBounds(290,120,100,25);
frame.add(tj);
JLabel label = new JLabel("Suma :");
label.setBounds(146,120,135,25);
label.setFont(new Font( "",Font.PLAIN, 14));
frame.add(label);
JLabel label2 = new JLabel ("Wynik :");
label2.setFont(new Font( "",Font.PLAIN, 14));
label2.setBounds(146,170,170,25);
frame.add(label2);
tj2.setBounds(290,170,100,25);
tj2.setFont(new Font( "",Font.PLAIN, 14));
frame.add(tj2);
button.addActionListener(new ActionDE());
JMenuBar menubar= new JMenuBar();
frame.setJMenuBar(menubar);
JMenu File = new JMenu("Opcje");
File.setMnemonic(KeyEvent.VK_O);
menubar.add(File);
JMenuItem r = new JMenuItem("okienko");
File.add(r);
r.addActionListener(new ActionKurs());
}
static class ActionDE implements ActionListener{
public void actionPerformed(ActionEvent e) {
double zahl=0;
try{
String a = tj.getText();
float b = Float.parseFloat(a);
if( e.getSource() == button)
zahl = b * x.Wyzmiana();
String s = String.valueOf( zahl );
tj2.setText(s);
}catch(NumberFormatException er){
JOptionPane.showMessageDialog (null, "Blad wpisu", "Blad:WSXP", 1);
}}}
static class ActionKurs implements ActionListener{
public void actionPerformed(ActionEvent e) {
x.w();
}}}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Klasa2 extends Klasa1 {
private double Nowy = 3;
static JFrame f = new JFrame();
static JTextField text = new JTextField("");
static JButton button = new JButton("zmien");
static JButton buttonclose = new JButton("");
static JLabel ar = new JLabel();
public void w(){
f.setTitle("liczba");
f.setSize(400,400);
f.setResizable(false);
f.setVisible(true);
f.setLayout(null);
Toolkit toolkit = getToolkit();
Dimension size = toolkit.getScreenSize();
f.setLocation(size.width/2 - f.getWidth()/2,size.height/2 - f.getHeight()/2);
text.setBounds(153,65,45,25);
f.add(text);
button.setBounds(210,65,100,25);
f.add(button);
button.addActionListener(new Actionkurs());
buttonclose.setBounds(310,330,60,30);
buttonclose.setBorder(BorderFactory.createBevelBorder(getDefaultCloseOperation(), Color.red , Color.blue));
f.add(buttonclose);
//ar.setIcon(new ImageIcon("icon.png"));
//ar.setBounds(320,65,22,22);
// f.add(ar);
// ar.setEnabled(false);
buttonclose.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ev ) {
f.dispose();
// ar.setEnabled(false);
// ar.setToolTipText("");
} } );
}
static class Actionkurs implements ActionListener{
public void actionPerformed(ActionEvent e) {
double b;
try{
String a = text.getText();
b = Double.parseDouble(a);
x.zmiana(b);
text.setText(a);
// ar.setEnabled(true);
// ar.setToolTipText("zmieniono");
}catch(NumberFormatException er){
Icon bee1 = new ImageIcon("error.png");
JOptionPane.showMessageDialog (null, "Blad wpisu", "Blad:WSXP", 1 , bee1);
}}}
public void zmiana(double zahl){
if(zahl==0)
this.Nowy=1;
else
this.Nowy= zahl;
}
public double Wyzmiana(){
return this.Nowy;
}}
public class First {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Klasa1 mkr = new Klasa1();
mkr.Klasa12();
}
}