2013-08-14 1 views
1

Я просто делаю небольшое приложение на строителе окон и нуждаюсь в некоторой помощи. Я сделал 2 кадра отдельно, и я не знаю, как указать действие кнопки таким образом, что, когда я нажимаю на «следующий» botton в первом кадре, я хочу, чтобы он переместился во второй кадр.Перемещение с одного кадра на другое в java swing

Вот исходный код для каждого файла.

first.java

import java.awt.BorderLayout; 
import java.awt.EventQueue; 

import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.border.EmptyBorder; 
import javax.swing.BoxLayout; 
import javax.swing.JButton; 
import javax.swing.JLabel; 
import javax.swing.JRadioButton; 
import javax.swing.JTextField; 
import javax.swing.AbstractAction; 

import java.awt.event.ActionEvent; 

import javax.swing.Action; 
import javax.swing.JTextArea; 
import java.awt.Font; 
import java.awt.event.ActionListener; 


public class first extends JFrame { 

private JPanel contentPane; 
private final Action action = new SwingAction(); 
private final Action action_1 = new SwingAction(); 

/** 
* Launch the application. 
*/ 
public static void main(String[] args) { 
    EventQueue.invokeLater(new Runnable() { 
     public void run() { 
      try { 
       first frame = new first(); 
       frame.setVisible(true); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    }); 
} 

/** 
* Create the frame. 
*/ 
public first() { 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    setBounds(100, 100, 450, 300); 
    contentPane = new JPanel(); 
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 
    setContentPane(contentPane); 
    contentPane.setLayout(null); 

    JButton btnNext = new JButton("Next"); 
    btnNext.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent arg0) { 
     } 
    }); 
    btnNext.setAction(action_1); 
    btnNext.setBounds(257, 228, 55, 23); 
    contentPane.add(btnNext); 

    JButton btnExit = new JButton("Exit"); 
    btnExit.setBounds(344, 228, 51, 23); 
    contentPane.add(btnExit); 

    JRadioButton rdbtnAdd = new JRadioButton("Add"); 
    rdbtnAdd.setBounds(27, 80, 109, 23); 
    contentPane.add(rdbtnAdd); 

    JRadioButton rdbtnDelete = new JRadioButton("Delete"); 
    rdbtnDelete.setBounds(27, 130, 109, 23); 
    contentPane.add(rdbtnDelete); 

    JRadioButton rdbtnEdit = new JRadioButton("Edit"); 
    rdbtnEdit.setBounds(27, 180, 109, 23); 
    contentPane.add(rdbtnEdit); 

    JLabel lblSelectAnOption = new JLabel("Select an Option"); 
    lblSelectAnOption.setFont(new Font("Tahoma", Font.PLAIN, 14)); 
    lblSelectAnOption.setBounds(27, 36, 121, 23); 
    contentPane.add(lblSelectAnOption); 
} 
private class SwingAction extends AbstractAction { 
    public SwingAction() { 
     putValue(NAME, "Next"); 
     putValue(SHORT_DESCRIPTION, "Some short description"); 
    } 
    public void actionPerformed(ActionEvent e) { 
     new second_add(); 
    } 
} 
} 

second.java

import java.awt.BorderLayout; 
    import java.awt.EventQueue; 

    import javax.swing.JFrame; 
    import javax.swing.JPanel; 
    import javax.swing.border.EmptyBorder; 
    import javax.swing.BoxLayout; 
    import javax.swing.JButton; 
    import javax.swing.JTextField; 
    import javax.swing.JComboBox; 
    import javax.swing.AbstractAction; 
    import java.awt.event.ActionEvent; 
    import javax.swing.Action; 
    import java.awt.event.ActionListener; 


    public class second_add extends JFrame { 

     private JPanel contentPane; 
     private JTextField txtTypeYourQuestion; 
     private JTextField txtQuestionWeight; 
     private JTextField txtEnter; 
     private JTextField txtEnter_1; 
     private JTextField txtValue; 
     private JTextField txtValue_1; 
     private final Action action = new SwingAction(); 

     /** 
     * Launch the application. 
     */ 
     public static void main(String[] args) { 
      EventQueue.invokeLater(new Runnable() { 
       public void run() { 
        try { 
         second_add frame = new second_add(); 
         frame.setVisible(true); 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
       } 
      }); 
     } 

     /** 
     * Create the frame. 
     */ 
     public second_add() { 
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      setBounds(100, 100, 450, 300); 
      contentPane = new JPanel(); 
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 
      setContentPane(contentPane); 
      contentPane.setLayout(null); 

      txtTypeYourQuestion = new JTextField(); 
      txtTypeYourQuestion.setBounds(22, 11, 177, 20); 
      txtTypeYourQuestion.setText("Type your Question Here"); 
      contentPane.add(txtTypeYourQuestion); 
      txtTypeYourQuestion.setColumns(10); 

      txtQuestionWeight = new JTextField(); 
      txtQuestionWeight.setBounds(209, 11, 86, 20); 
      txtQuestionWeight.setText("Question weight"); 
      contentPane.add(txtQuestionWeight); 
      txtQuestionWeight.setColumns(10); 

      txtEnter = new JTextField(); 
      txtEnter.setBounds(22, 55, 86, 20); 
      txtEnter.setText("Enter . . ."); 
      contentPane.add(txtEnter); 
      txtEnter.setColumns(10); 

      txtEnter_1 = new JTextField(); 
      txtEnter_1.setText("Enter . . . "); 
      txtEnter_1.setBounds(22, 104, 86, 20); 
      contentPane.add(txtEnter_1); 
      txtEnter_1.setColumns(10); 

      txtValue = new JTextField(); 
      txtValue.setText("Value . ."); 
      txtValue.setBounds(118, 55, 51, 20); 
      contentPane.add(txtValue); 
      txtValue.setColumns(10); 

      txtValue_1 = new JTextField(); 
      txtValue_1.setText("Value . ."); 
      txtValue_1.setBounds(118, 104, 51, 20); 
      contentPane.add(txtValue_1); 
      txtValue_1.setColumns(10); 

      JButton btnFinish = new JButton("Finish"); 
      btnFinish.addActionListener(new ActionListener() { 
       public void actionPerformed(ActionEvent e) { 
       } 
      }); 
      btnFinish.setAction(action); 
      btnFinish.setBounds(335, 228, 89, 23); 
      contentPane.add(btnFinish); 

      JButton btnAddChoice = new JButton("Add choice"); 
      btnAddChoice.setBounds(236, 228, 89, 23); 
      contentPane.add(btnAddChoice); 

      JButton btnAddQuestion = new JButton("Add question"); 
      btnAddQuestion.setBounds(136, 228, 89, 23); 
      contentPane.add(btnAddQuestion); 

     } 
     private class SwingAction extends AbstractAction { 
      public SwingAction() { 
       putValue(NAME, ""); 
       putValue(SHORT_DESCRIPTION, "Some short description"); 
      } 
      public void actionPerformed(ActionEvent e) { 
      } 
     } 
    } 

ответ

0

Изменить как this-

JButton btnNext = new JButton("Next"); 
btnNext.addActionListener(new ActionListener() { 
    public void actionPerformed(ActionEvent arg0) { 
     second_add second = new second_add(); 
     setVisible(false); // Hide current frame 
     second.setVisible(true); 
    } 
}); 
1

быстрый и грязный раствор будет установить видимость первого кадра к ложным и вторая видимость кадров в true в действии buttonclick. (См ответ Sajal Датта в)

Но иметь согласованное поведение даже более 2-х кадров, пусть каждый кадр будет храниться в HashTable в главном классе (класс держит метод main и не расширения JFrame) с ID - порядок кадра (первый кадр D 1, второй: идентификатор 2 и т. Д.).

Затем создайте статический метод

public void switchFrame(JFrame originatingFrame, int NextFrame){ 
    originatingFrame.this.setVisible(false); 
    ((JFrame) myHashTable.get(NextFrame)).setVisible(true); 
} 

в основной класс, который может быть вызван из каждого кадра с помощью

mainClass.switchFrame(this, IdOfFrameYouWantToGoTo); 

таким образом, вы также можете реализовать «Назад» - и «Пропустить» - Кнопки, если вы хотите создать что-то вроде мастера.

ПРИМЕЧАНИЕ: Я не тестировал этот код. Это следует рассматривать только как общий обзор того, как это сделать.

2
  • Имея несколько экземпляров JFrame в одном приложении плохо Юзабилити
  • рассмотреть вопрос об использовании нечто вроде CardLayout вместо этого.
+2

Почему мой ответ был отредактирован, чтобы указать на другое обсуждение этого вопроса? Я даже не знал об этом конкретном вопросе, когда я отправил свой ответ. Я могу понять редактирование для форматирования или ссылки на javadocs, но изменить его на URL-адрес, чтобы указать на чужой ответ, неверно. Пожалуйста, отмените ложную ссылку – maneesh

+1

ОК, неважно. Я сам отредактировал. Если вы хотите предоставить дополнительную информацию/ссылки, во что бы то ни стало, сделайте это. Просто НЕ ПРЕДОСТАВЛЯЙТЕ их в моих ответах. – maneesh

0

Вы можете перейти к кадру, создав его объект и используя метод setVisible для его отображения. Если вы хотите сделать это нажатием кнопки, напишите его внутри своего обработчика событий.

JFrame o = new JFrame(); 
o.setVisible(true); 
dispose();  // This will close the current frame 
0

Ниже представлен фрагмент кода для перехода с одной страницы на другую в формате меню.

import java.awt.BorderLayout; 
    import java.awt.Button; 
    import java.awt.CardLayout; 
    import java.awt.Container; 
    import java.awt.GraphicsEnvironment; 
    import java.awt.GridBagConstraints; 
    import java.awt.GridBagLayout; 
    import java.awt.GridLayout; 
    import java.awt.Insets; 
    import java.awt.Panel; 
    import java.awt.TextArea; 
    import java.awt.event.ActionEvent; 
    import java.awt.event.ActionListener; 
    import java.awt.event.WindowEvent; 
    import java.io.IOException; 
    import java.io.PipedInputStream; 
    import java.io.PipedOutputStream; 
    import java.io.PrintStream; 
    import java.util.ArrayList; 

    import javax.swing.JButton; 
    import javax.swing.JComboBox; 
    import javax.swing.JFrame; 
    import javax.swing.JLabel; 
    import javax.swing.JMenu; 
    import javax.swing.JMenuBar; 
    import javax.swing.JMenuItem; 
    import javax.swing.JOptionPane; 
    import javax.swing.JPanel; 
    import javax.swing.JPasswordField; 
    import javax.swing.JTextField; 

public class AddressBookDemo implements ActionListener, Runnable { 

    ArrayList personsList; 
    PersonDAO pDAO; 
    Panel panel; 
    JFrame appFrame; 
    JLabel jlbName, jblPassword, jlbAddress; 
    JPasswordField jPassword; 
    JTextField jtfName, jtfAddress; 
    JButton jbbSave, jbnClear, jbnExit, btnNext, button; 
    String name, address, password; 
    final int CARDS = 4; 
    CardLayout cl = new CardLayout(); 
    JPanel cardPanel = new JPanel(cl); 
    CardLayout c2 = new CardLayout(); 
    JPanel cardPanel2 = new JPanel(c2); 
    int currentlyShowing = 0; 
    Thread errorThrower; 
    // int phone; 
    // int recordNumber; // used to naviagate using >> and buttons 
    Container cPane; 
    Container cPane2; 

    private JFrame frame; 
    private TextArea textArea; 
    private Thread reader; 
    private Thread reader2; 
    private boolean quit; 

    private final PipedInputStream pin = new PipedInputStream(); 
    private final PipedInputStream pin2 = new PipedInputStream(); 
    public static void main(String args[]) { 
     new AddressBookDemo(); 
    } 

    public AddressBookDemo() { 
     name = ""; 
     password = ""; 
     address = ""; 
     // phone = -1; //Stores 0 to indicate no Phone Number 
     // recordNumber = -1; 
     createGUI(); 
     personsList = new ArrayList(); 
     // creating PersonDAO object 
     pDAO = new PersonDAO(); 
    } 

    public void createGUI() { 

     /* Create a frame, get its contentpane and set layout */ 
     appFrame = new JFrame("ManualDeploy "); 
     cPane = appFrame.getContentPane(); 
     cPane.setLayout(new GridBagLayout()); 
//  frame=new JFrame("Java Console"); 
     textArea=new TextArea(); 
     textArea.setEditable(false); 
     Button button=new Button("clear"); 

     panel=new Panel(); 
     panel.setLayout(new GridBagLayout()); 
     GridBagConstraints gridBagConstraintsx01 = new GridBagConstraints(); 
     gridBagConstraintsx01.gridx = 0; 
     gridBagConstraintsx01.gridy = 0; 
     gridBagConstraintsx01.insets = new Insets(5, 5, 5, 5); 
     panel.add(textArea,gridBagConstraintsx01); 
     GridBagConstraints gridBagConstraintsx03 = new GridBagConstraints(); 
     gridBagConstraintsx03.gridx = 0; 
     gridBagConstraintsx03.insets = new Insets(5, 5, 5, 5); 
     gridBagConstraintsx03.gridy = 1; 
     panel.add(button,gridBagConstraintsx03); 
//  frame.add(panel); 

//  frame.setVisible(true);  
//  cPane2 = frame.getContentPane(); 
//  cPane2.setLayout(new GridBagLayout()); 
     button.addActionListener(this); 

     try 
     { 
      PipedOutputStream pout=new PipedOutputStream(this.pin); 
      System.setOut(new PrintStream(pout,true)); 
     } 
     catch (java.io.IOException io) 
     { 
      textArea.append("Couldn't redirect STDOUT to this console\n"+io.getMessage()); 
     } 
     catch (SecurityException se) 
     { 
      textArea.append("Couldn't redirect STDOUT to this console\n"+se.getMessage()); 
     } 

     try 
     { 
      PipedOutputStream pout2=new PipedOutputStream(this.pin2); 
      System.setErr(new PrintStream(pout2,true)); 
     } 
     catch (java.io.IOException io) 
     { 
      textArea.append("Couldn't redirect STDERR to this console\n"+io.getMessage()); 
     } 
     catch (SecurityException se) 
     { 
      textArea.append("Couldn't redirect STDERR to this console\n"+se.getMessage()); 
     }  

     quit=false; // signals the Threads that they should exit 

     // Starting two seperate threads to read from the PipedInputStreams    
     // 
     reader=new Thread(this); 
     reader.setDaemon(true); 
     reader.start(); 
     // 
     reader2=new Thread(this); 
     reader2.setDaemon(true);  
     reader2.start(); 

     // testing part 
     // you may omit this part for your application 
     // 
     System.out.println("Hello World 2"); 
     System.out.println("All fonts available to Graphic2D:\n"); 
     GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
     String[] fontNames=ge.getAvailableFontFamilyNames(); 
     for(int n=0;n<fontNames.length;n++) System.out.println(fontNames[n]);  
     // Testing part: simple an error thrown anywhere in this JVM will be printed on the Console 
     // We do it with a seperate Thread becasue we don't wan't to break a Thread used by the Console. 
     System.out.println("\nLets throw an error on this console");  
     errorThrower=new Thread(this); 
     errorThrower.setDaemon(true); 
     errorThrower.start(); 



     arrangeComponents(); 
     // arrangeComponents2(); 
     final int CARDS = 2; 
     final CardLayout cl = new CardLayout(); 
     final JPanel cardPanel = new JPanel(cl); 
     JMenu menu = new JMenu("M"); 
     for (int x = 0; x < CARDS; x++) { 
      final int SELECTION = x; 
      JPanel jp = new JPanel(); 
      if (x == 0) { 
       jp.add(cPane); 
      } else if (x == 1) { 
       jp.add(panel); 
      } else if (x == 2) 
       jp.add(new JButton("Panel 2")); 
      else 
       jp.add(new JComboBox(new String[] { "Panel 3" })); 
      cardPanel.add("" + SELECTION, jp); 
      JMenuItem menuItem = new JMenuItem("Show Panel " + x); 
      menuItem.addActionListener(new ActionListener() { 
       public void actionPerformed(ActionEvent ae) { 
        currentlyShowing = SELECTION; 
        cl.show(cardPanel, "" + SELECTION); 
       } 
      }); 
      menu.add(menuItem); 
     } 
     JMenuBar menuBar = new JMenuBar(); 
     menuBar.add(menu); 

     btnNext = new JButton("Next >>"); 

     JButton btnPrev = new JButton("<< Previous"); 
     JPanel p = new JPanel(new GridLayout(1, 2)); 
     p.add(btnPrev); 
     p.add(btnNext); 
     btnNext.setVisible(false); 
     JFrame f = new JFrame(); 
     f.getContentPane().add(cardPanel); 
     f.getContentPane().add(p, BorderLayout.SOUTH); 
     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     f.setSize(500, 500); 
     f.setLocationRelativeTo(null); 
     f.setJMenuBar(menuBar); 
     f.setVisible(true); 
     btnNext.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent ae) { 
       if (currentlyShowing < CARDS - 1) { 
        cl.next(cardPanel); 
        currentlyShowing++; 
       } 
      } 
     }); 
     btnPrev.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent ae) { 
       if (currentlyShowing > 0) { 
        cl.previous(cardPanel); 
        currentlyShowing--; 
       } 
      } 
     }); 

    } 

    public void arrangeComponents() { 
     jlbName = new JLabel("Username"); 
     jblPassword = new JLabel("Password"); 
     jlbAddress = new JLabel("Sftpserver"); 
     jtfName = new JTextField(20); 
     jPassword = new JPasswordField(20); 
     jtfAddress = new JTextField(20); 
     jbbSave = new JButton("move sftp"); 
     jbnClear = new JButton("Clear"); 
     jbnExit = new JButton("Exit"); 
     /* add all initialized components to the container */ 
     GridBagConstraints gridBagConstraintsx01 = new GridBagConstraints(); 
     gridBagConstraintsx01.gridx = 0; 
     gridBagConstraintsx01.gridy = 0; 
     gridBagConstraintsx01.insets = new Insets(5, 5, 5, 5); 
     cPane.add(jlbName, gridBagConstraintsx01); 
     GridBagConstraints gridBagConstraintsx02 = new GridBagConstraints(); 
     gridBagConstraintsx02.gridx = 1; 
     gridBagConstraintsx02.insets = new Insets(5, 5, 5, 5); 
     gridBagConstraintsx02.gridy = 0; 
     gridBagConstraintsx02.gridwidth = 2; 
     gridBagConstraintsx02.fill = GridBagConstraints.BOTH; 
     cPane.add(jtfName, gridBagConstraintsx02); 
     GridBagConstraints gridBagConstraintsx03 = new GridBagConstraints(); 
     gridBagConstraintsx03.gridx = 0; 
     gridBagConstraintsx03.insets = new Insets(5, 5, 5, 5); 
     gridBagConstraintsx03.gridy = 1; 
     cPane.add(jblPassword, gridBagConstraintsx03); 
     GridBagConstraints gridBagConstraintsx04 = new GridBagConstraints(); 
     gridBagConstraintsx04.gridx = 1; 
     gridBagConstraintsx04.insets = new Insets(5, 5, 5, 5); 
     gridBagConstraintsx04.gridy = 1; 
     gridBagConstraintsx04.gridwidth = 2; 
     gridBagConstraintsx04.fill = GridBagConstraints.BOTH; 
     cPane.add(jPassword, gridBagConstraintsx04); 
     GridBagConstraints gridBagConstraintsx05 = new GridBagConstraints(); 
     gridBagConstraintsx05.gridx = 0; 
     gridBagConstraintsx05.insets = new Insets(5, 5, 5, 5); 
     gridBagConstraintsx05.gridy = 2; 
     cPane.add(jlbAddress, gridBagConstraintsx05); 
     GridBagConstraints gridBagConstraintsx06 = new GridBagConstraints(); 
     gridBagConstraintsx06.gridx = 1; 
     gridBagConstraintsx06.gridy = 2; 
     gridBagConstraintsx06.insets = new Insets(5, 5, 5, 5); 
     gridBagConstraintsx06.gridwidth = 2; 
     gridBagConstraintsx06.fill = GridBagConstraints.BOTH; 
     cPane.add(jtfAddress, gridBagConstraintsx06); 
     GridBagConstraints gridBagConstraintsx09 = new GridBagConstraints(); 
     gridBagConstraintsx09.gridx = 0; 
     gridBagConstraintsx09.gridy = 4; 
     gridBagConstraintsx09.insets = new Insets(5, 5, 5, 5); 
     cPane.add(jbbSave, gridBagConstraintsx09); 
     GridBagConstraints gridBagConstraintsx10 = new GridBagConstraints(); 
     gridBagConstraintsx10.gridx = 1; 
     gridBagConstraintsx10.gridy = 4; 
     gridBagConstraintsx10.insets = new Insets(5, 5, 5, 5); 
     cPane.add(jbnClear, gridBagConstraintsx10); 
     GridBagConstraints gridBagConstraintsx11 = new GridBagConstraints(); 
     gridBagConstraintsx11.gridx = 2; 
     gridBagConstraintsx11.gridy = 4; 
     gridBagConstraintsx11.insets = new Insets(5, 5, 5, 5); 
     cPane.add(jbnExit, gridBagConstraintsx11); 
     jbbSave.addActionListener(this); 
     // jbnDelete.addActionListener(this); 
     jbnClear.addActionListener(this); 
     jbnExit.addActionListener(this); 
    } 

    public void actionPerformed(ActionEvent e) { 
     System.out.println("inside button123"); 
     if (e.getSource() == jbbSave) { 
      savePerson(); 
     } else if (e.getSource() == jbnClear) { 
      clear(); 
     } else if (e.getSource() == jbnExit) { 
      System.exit(0); 
     } 
     else if (e.getSource() == button) 
     { 
      System.out.println("inside button"); 
      textArea.setText(" "); 
     } 
    } 

    // Save the Person into the Address Book 
    public void savePerson() { 
     name = jtfName.getText(); 
     password = jPassword.getText(); 
     address = jtfAddress.getText(); 
     if (name.equals("")) { 
      JOptionPane.showMessageDialog(null, "Please enter password", 
        "ERROR", JOptionPane.ERROR_MESSAGE); 
     } else if (password != null && password.isEmpty()) { 
      JOptionPane.showMessageDialog(null, "Please enter password", 
        "ERROR", JOptionPane.ERROR_MESSAGE); 
     } 

     else { 
      btnNext.setVisible(true); 
      JOptionPane.showMessageDialog(null, "Person Saved"); 
     } 
    } 

    public void clear() { 
     jtfName.setText(""); 
     jPassword.setText(""); 
     jtfAddress.setText(""); 
     personsList.clear(); 
    } 

    public synchronized void run() 
    { 
     try 
     {   
      while (Thread.currentThread()==reader) 
      { 
       try { this.wait(100);}catch(InterruptedException ie) {} 
       if (pin.available()!=0) 
       { 
        String input=this.readLine(pin); 
        textArea.append(input); 
       } 
       if (quit) return; 
      } 

      while (Thread.currentThread()==reader2) 
      { 
       try { this.wait(100);}catch(InterruptedException ie) {} 
       if (pin2.available()!=0) 
       { 
        String input=this.readLine(pin2); 
        textArea.append(input); 
       } 
       if (quit) return; 
      }   
     } catch (Exception e) 
     { 
      textArea.append("\nConsole reports an Internal error."); 
      textArea.append("The error is: "+e);    
     } 

     // just for testing (Throw a Nullpointer after 1 second) 
//  if (Thread.currentThread()==errorThrower) 
//  { 
//   try { this.wait(1000); }catch(InterruptedException ie){} 
//   throw new NullPointerException("Application test: throwing an NullPointerException It should arrive at the console"); 
//  } 

    } 

    public synchronized String readLine(PipedInputStream in) throws IOException 
    { 
     String input=""; 
     do 
     { 
      int available=in.available(); 
      if (available==0) break; 
      byte b[]=new byte[available]; 
      in.read(b); 
      input=input+new String(b,0,b.length);              
     }while(!input.endsWith("\n") && !input.endsWith("\r\n") && !quit); 
     return input; 
    } 
    public synchronized void windowClosed(WindowEvent evt) 
    { 
     quit=true; 
     this.notifyAll(); // stop all threads 
     try { reader.join(1000);pin.close(); } catch (Exception e){}  
     try { reader2.join(1000);pin2.close(); } catch (Exception e){} 
     System.exit(0); 
    }  



}