решила вопрос с диалоговым окном, теперь проблема с перехватом событий ниже приведен листинг, объясните пожалуста почему событие нажатия на кнопку срабатывает, даже когда это событие не произошло(например при запуске программки и когда просто разворачиваешь свёрнутое окно фрэйма)?
| Код | import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.ComponentEvent; import java.io.*; import java.lang.*; import java.lang.String; import java.lang.Math.*; import javax.swing.*;
public class Lab2 extends Frame { TextArea txt_mas; static TextArea txt_smas; static TextArea txt_mi; Button get_mas; static Double mas[]; static int Mi[]={0,0,0,0,0,0}; static double h; static int K; static FileDialog dialog;
public Lab2() { get_mas=new Button("Get Array from File"); get_mas.setBounds(10,40, 120, 25); super.add(get_mas);
txt_mas=new TextArea(); txt_mas.setBounds(10,80,60,630); super.add(txt_mas);
txt_smas=new TextArea(); txt_smas.setBounds(80,80,60,630); super.add(txt_smas);
txt_mi=new TextArea(); txt_mi.setBounds(160,80,60,110); super.add(txt_mi);
int width = 1020; int height = 850; super.setSize(width, height); super.setLayout(null); super.setVisible(true); }
public boolean handleEvent(Event evt) { if(evt.id==Event.WINDOW_DESTROY ) { dispose(); return true; } else if(evt.target.equals(get_mas)) { dialog.setDirectory("D:\\5-course\\EXP\\Lab02"); dialog.show(); txt_mas.setText(""); try { File file=new File(dialog.getDirectory()+"\\"+dialog.getFile()); FileInputStream fis=new FileInputStream(file); DataInputStream dis=new DataInputStream(fis); String line=dis.readLine(); String []tmp = line.split(","); mas = new Double [tmp.length]; for(int i=0;i<mas.length;i++) { mas[i] = new Double(tmp[i]); txt_mas.appendText(String.valueOf(mas[i])+"\n"); } this.repaint();
} catch(IOException e) { System.out.println("error = "+e); } return true; } else return super.handleEvent(evt); }
public static void main(String args[]) { Lab2 lab=new Lab2(); dialog=new FileDialog(lab,"Open"); }
public void paint(Graphics g) { //тут я рисую всякие графики } }
| |