Hi:

I made a java app. (with 3 windows) and I was wondering if there was a way to close two of the three forms (except one window) without closing the entire application (All 3 windows).

Thanx in advanced,
C++

they're just in a separte class - they're just JFrames. Here's the code.

Thanx for your help,
C++

/****************************\
 *  Copyright (c) 2004 CRD   *
 *  Author Ian Cinnamon      *
 *  Version Number: 2.0      *
 *  Decrypter                *
 *                           *
 \***************************/


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;

class cryptC extends JFrame implements ActionListener{

  ImageIcon LargePic = new ImageIcon("large.jpg");
  ImageIcon SmallPic = new ImageIcon("small.jpg");

  private UIManager.LookAndFeelInfo looks[];

  JLabel lbl = new JLabel("En/De Crypter");
  JButton small = new JButton("Special Edition mini Decrypter",SmallPic);
  JButton large = new JButton("     ***   Default Decrypter   ***  ",LargePic);
  Font cf = new Font("Times New Roman",Font.BOLD,24);

  public cryptC(){
    super("Decrypter v. 2.0");
    setSize(280,200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

    looks = UIManager.getInstalledLookAndFeels();

    try{
      UIManager.setLookAndFeel(looks[2].getClassName());
      SwingUtilities.updateComponentTreeUI(this);
    }
    catch(Exception excep){
      excep.printStackTrace();
    }

    Container content = getContentPane();
    FlowLayout lay = new FlowLayout();
    content.setLayout(lay);

    content.add(lbl);
    content.setBackground(Color.WHITE);
    content.add(small);
    small.setBackground(Color.CYAN);
    content.add(large);
    large.setBackground(Color.CYAN);

    small.addActionListener(this);
    large.addActionListener(this);


    lbl.setFont(cf);

    setContentPane(content);

  }
  public void actionPerformed(ActionEvent event){
    if(event.getSource() == small){
      new cryptM();
    }
    if(event.getSource() == large){
      new crypt();
    }
  }
  public static void main(String [] args){
    new cryptC();
  }
}


//Crypter, MINI Edition
class cryptM extends JFrame implements ActionListener{

  private UIManager.LookAndFeelInfo looks[];

  ImageIcon LargePic = new ImageIcon("large.jpg");
  ImageIcon SmallPic = new ImageIcon("small.jpg");
  ImageIcon CryptPic = new ImageIcon("crypt.jpg");

  JLabel lbl = new JLabel("The Decrypter");
  JButton help = new JButton("Help Me");
  JButton go = new JButton("Encrypt / Decrypt",CryptPic);
  JButton save = new JButton("Save to...");
  JButton open = new JButton("Open from...");
  JButton big = new JButton("Default Encrypter",LargePic);

  BufferedWriter buffer2;

  Font cf = new Font("Times New Roman", Font.BOLD, 24);

  public String origS = "";

  public cryptM(){
    super("Decrypter v. 2.0");
    setSize(220,260);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

    looks = UIManager.getInstalledLookAndFeels();
    try{
      UIManager.setLookAndFeel(looks[2].getClassName());
      SwingUtilities.updateComponentTreeUI(this);
    }
    catch(Exception excep){
      excep.printStackTrace();
    }


    Container content = getContentPane();
    FlowLayout lay = new FlowLayout();
    content.setLayout(lay);

    lbl.setForeground(Color.WHITE);
    lbl.setFont(cf);
    content.add(lbl);

    content.add(save);
    save.setBackground(Color.WHITE);
    content.add(open);
    open.setBackground(Color.WHITE);
    content.add(go);
    go.setBackground(Color.RED);
    content.add(help);
    help.setBackground(Color.BLACK);
    help.setForeground(Color.WHITE);
    content.add(big);
    big.setBackground(Color.ORANGE);

    content.setBackground(Color.BLACK);


    go.addActionListener(this);
    help.addActionListener(this);
    save.addActionListener(this);
    open.addActionListener(this);
    big.addActionListener(this);

    setContentPane(content);


  }
  public void actionPerformed(ActionEvent event){
    if(event.getSource() == go){
      change();
    }
    if(event.getSource() == help){
      JOptionPane.showMessageDialog(null,
          "Type in the path of the original .txt file.\n"+
          "The new file will be saved in the pre decided path.\n"+
          "\n\n"+
          "For more help, email code.rocket@gmail.com",
          "Help Me",
          JOptionPane.INFORMATION_MESSAGE);
    }
    if(event.getSource() == big){
      new crypt();
    }
    if(event.getSource() == open){
      try{
        FileReader file = new FileReader(JOptionPane.showInputDialog(
            null, "Please enter the path of the file that\n"+
            "will be opened.",
            "Enter Path", JOptionPane.QUESTION_MESSAGE));
        BufferedReader buffer = new BufferedReader(file);
        origS = buffer.readLine();
        buffer.close();
      }
      catch(Exception ex){
        JOptionPane.showMessageDialog(null,"Error opening file.","Error",
                                      JOptionPane.ERROR_MESSAGE);
      }
    }
    if(event.getSource() == save){
      try {
        FileWriter file2 = new FileWriter(JOptionPane.showInputDialog(
            null, "Please enter the path of where the file should\n" +
            "be saved to.", "Enter Path", JOptionPane.QUESTION_MESSAGE));

        buffer2 = new BufferedWriter(file2);


      }
      catch (Exception e) {

      }
    }
  }
  public void change(){
     char let[] = origS.toCharArray();
     int len1 = let.length;
     int len = len1--;
     int i;
     for(i = 0; i < len; i++){

       switch (let[i]) {

         case ' ':
           let[i] = 'A';
           break;
         case 'A':
           let[i] = ' ';
           break;

         case '!':
          let[i] = 'Z';
          break;
        case 'Z':
          let[i] = '!';
          break;

        case '"':
         let[i] = '#';
         break;
       case '#':
         let[i] = '"';
         break;

       case 'q':
         let[i] = '$';
         break;
       case '$':
         let[i] = 'q';
         break;

       case 'z':
         let[i] = '%';
         break;
       case '%':
         let[i] = 'z';
         break;

       case '&':
         let[i] = 'i';
         break;
       case 'i':
         let[i] = '&';
         break;

       case 39:
         let[i] = 'a';
         break;
       case 'a':
         let[i] = 39;
         break;

       case '(':
         let[i] = 'J';
         break;
       case 'J':
         let[i] = '(';
         break;

       case ')':
         let[i] = 'C';
         break;
       case 'C':
         let[i] = ')';
         break;

       case '*':
         let[i] = '3';
         break;
       case '3':
         let[i] = '*';
         break;

       case '+':
         let[i] = ';';
         break;
       case ';':
         let[i] = '+';
         break;

       case ',':
         let[i] = ']';
         break;
       case ']':
         let[i] = ',';
         break;

       case '-':
         let[i] = '/';
         break;
       case '/':
         let[i] = '-';
         break;

       case '.':
         let[i] = '6';
         break;
       case '6':
         let[i] = '.';
         break;

       case '0':
         let[i] = '9';
         break;
       case '9':
         let[i] = '0';
         break;

       case '4':
         let[i] = 'T';
         break;
       case 'T':
         let[i] = '4';
         break;

       case '5':
         let[i] = 'W';
         break;
       case 'W':
         let[i] = '5';
         break;

       case '7':
         let[i] = 'O';
         break;
       case 'O':
         let[i] = '7';
         break;

       case '8':
         let[i] = 'w';
         break;
       case 'w':
         let[i] = '8';
         break;

       case ':':
         let[i] = 'Y';
         break;
       case 'Y':
         let[i] = ':';
         break;

       case '<':
         let[i] = 'y';
         break;
       case 'y':
         let[i] = '<';
         break;

       case '=':
         let[i] = 92;
         break;
       case 92:
         let[i] = '=';
         break;

       case '>':
         let[i] = '_';
         break;
       case '_':
         let[i] = '>';
         break;

       case '?':
         let[i] = '^';
         break;
       case '^':
         let[i] = '?';
         break;

       case '@':
         let[i] = '`';
         break;
       case '`':
         let[i] = '@';
         break;

     case 'B':
       let[i] = 'e';
       break;
     case 'e':
       let[i] = 'B';
       break;

     case 'D':
       let[i] = 'c';
       break;
     case 'c':
       let[i] = 'D';
       break;

     case 'E':
       let[i] = '~';
       break;
     case '~':
       let[i] = 'E';
       break;

     case 'F':
       let[i] = 'n';
       break;
     case 'n':
       let[i] = 'F';
       break;

     case 'G':
       let[i] = 'j';
       break;
     case 'j':
       let[i] = 'G';
       break;

     case 'H':
       let[i] = 'b';
       break;
     case 'b':
       let[i] = 'H';
       break;

     case 'I':
       let[i] = '}';
       break;
     case '}':
       let[i] = 'I';
       break;

     case 'K':
       let[i] = 'g';
       break;
     case 'g':
       let[i] = 'K';
       break;

     case 'L':
       let[i] = 'S';
       break;
     case 'S':
       let[i] = 'L';
       break;

     case 'M':
       let[i] = 'N';
       break;
     case 'N':
       let[i] = 'M';
       break;

     case 'P':
       let[i] = 'U';
       break;
     case 'U':
       let[i] = 'P';
       break;

     case 'Q':
       let[i] = 'u';
       break;
     case 'u':
       let[i] = 'Q';
       break;

     case 'R':
       let[i] = 'p';
       break;
     case 'p':
       let[i] = 'R';
       break;

     case 'V':
       let[i] = 'v';
       break;
     case 'v':
       let[i] = 'V';
       break;

     case 'X':
       let[i] = '|';
       break;
     case '|':
       let[i] = 'X';
       break;

     case '[':
       let[i] = '{';
       break;
     case '{':
       let[i] = '[';
       break;

     case 'd':
       let[i] = 'h';
       break;
     case 'h':
       let[i] = 'd';
       break;

     case 'f':
       let[i] = 'k';
       break;
     case 'k':
       let[i] = 'f';
       break;

     case 'm':
       let[i] = 's';
       break;
     case 's':
       let[i] = 'm';
       break;

     case 'o':
       let[i] = 'r';
       break;
     case 'r':
       let[i] = 'o';
       break;

     case 't':
       let[i] = 'x';
       break;
     case 'x':
       let[i] = 't';
       break;

       }
     }

       String NewS = "";

       for(int d = 0; d < let.length; d++){
         NewS+=let[d];
       }

       origS = NewS;

       try{
         buffer2.write(origS);
         buffer2.close();
       }
       catch(Exception exception){
         JOptionPane.showMessageDialog(null,"Error writing file.","Error",
                                      JOptionPane.ERROR_MESSAGE);
       }

  }

}








//Crypter, Large Version
class crypt extends JFrame implements ActionListener
{

  private UIManager.LookAndFeelInfo looks[];

  ImageIcon LargePic = new ImageIcon("large.jpg");
  ImageIcon SmallPic = new ImageIcon("small.jpg");
  ImageIcon CryptPic = new ImageIcon("crypt.jpg");

  JLabel lbl = new JLabel("The Decrypter");
  JButton help = new JButton("Help Me");
  JTextArea in = new JTextArea("Enter the text that should be changed here.", 15, 45);
  JTextArea out = new JTextArea("NEW TEXT GOES HERE...", 15, 45);
  JButton go = new JButton(" Encrypt",CryptPic);
  JButton go2 = new JButton(" Decrypt",CryptPic);
  JButton save = new JButton("Save");
  JButton open = new JButton("Open");
  JButton exit = new JButton("Exit");
  JButton mini = new JButton("Switch to Mini Encrypter",SmallPic);
  JPopupMenu menu;

  Font cf = new Font("Times New Roman", Font.BOLD, 34);
  Font cf2 = new Font("Arial",Font.BOLD,20);

  public String origS;
  public String origS2;

  public crypt()
  {
    super("Decrypter v. 2.0");
    setSize(500,730);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

    looks = UIManager.getInstalledLookAndFeels();
    try{
          UIManager.setLookAndFeel(looks[2].getClassName());
          SwingUtilities.updateComponentTreeUI(this);
    }
    catch(Exception excep){
          excep.printStackTrace();
    }


    Container content = getContentPane();
    FlowLayout lay = new FlowLayout();
    content.setLayout(lay);

    menu = new JPopupMenu();
    menu.add(save);
    menu.add(open);
    menu.add(exit);

    save.setBackground(Color.BLUE);
    open.setBackground(Color.BLUE);
    exit.setBackground(Color.BLUE);
    save.setForeground(Color.RED);
    open.setForeground(Color.RED);
    exit.setForeground(Color.RED);

    menu.setBackground(Color.GREEN);


    addMouseListener(
      new MouseAdapter(){
        public void mousePressed(MouseEvent event){
          checkForTriggerEvent(event);
        }
        public void mouseReleased(MouseEvent event){
          checkForTriggerEvent(event);
        }
        private void checkForTriggerEvent(MouseEvent event){
          if(event.isPopupTrigger()){
            menu.show(event.getComponent(), event.getX(), event.getY());
          }
        }
      }
    );


    lbl.setForeground(Color.WHITE);
    lbl.setFont(cf);
    content.add(lbl);

    in.setBackground(Color.WHITE);
    content.add(new JScrollPane(in));
    content.add(go);
    go.setBackground(Color.RED);
    content.add(go2);
    go.setFont(cf2);
    go2.setBackground(Color.RED);
    go2.setFont(cf2);
    content.add(new JScrollPane(out));
    out.setBackground(Color.WHITE);
    content.add(mini);
    mini.setBackground(Color.ORANGE);
    content.add(help);
    help.setBackground(Color.BLACK);
    help.setForeground(Color.WHITE);

    content.setBackground(Color.BLACK);


    go.addActionListener(this);
    go2.addActionListener(this);
    help.addActionListener(this);
    save.addActionListener(this);
    open.addActionListener(this);
    exit.addActionListener(this);
    mini.addActionListener(this);

    setContentPane(content);
  }
  public void actionPerformed(ActionEvent event){

    if(event.getSource() == go){
      origS = in.getText();
      change();
    }
    if(event.getSource() == go2){
      origS = in.getText();
      change();
    }


    if(event.getSource() == help){
      JOptionPane.showMessageDialog(null,
          "Put the original file in the first box.\n"+
          "The new file will go in the second box.\n"+
          "\n\n"+
          "For more help, email code.rocket@gmail.com",
          "Help Me",
          JOptionPane.INFORMATION_MESSAGE);
    }
    if(event.getSource() == exit){
      System.exit(1);
    }
    if(event.getSource() == save){
      try{
        FileWriter file = new FileWriter(JOptionPane.showInputDialog(
            null, "Please enter the path of where the file should\n" +
            "be saved to.", "Enter Path", JOptionPane.QUESTION_MESSAGE));

        BufferedWriter buffer = new BufferedWriter(file);

        buffer.write(out.getText());
        buffer.close();
      }
      catch(Exception e){
        JOptionPane.showMessageDialog(null,"Error writing file.","Error",
                                      JOptionPane.ERROR_MESSAGE);
      }
    }
    if(event.getSource() == open){
      try{
        FileReader file2 = new FileReader(JOptionPane.showInputDialog(
            null, "Please enter the path of the file that\n"+
            "will be opened.",
            "Enter Path", JOptionPane.QUESTION_MESSAGE));
        BufferedReader buffer2 = new BufferedReader(file2);
        in.setText(buffer2.readLine());
        buffer2.close();
      }
      catch(Exception ex){
        JOptionPane.showMessageDialog(null,"Error opening file.","Error",
                                      JOptionPane.ERROR_MESSAGE);
      }
    }
    if(event.getSource() == mini){
      new cryptM();
    }
  }

  public void change(){
     char let[] = origS.toCharArray();
     int len1 = let.length;
     int len = len1--;
     int i;
     for(i = 0; i < len; i++){

       switch (let[i]) {

         case ' ':
           let[i] = 'A';
           break;
         case 'A':
           let[i] = ' ';
           break;

         case '!':
          let[i] = 'Z';
          break;
        case 'Z':
          let[i] = '!';
          break;

        case '"':
         let[i] = '#';
         break;
       case '#':
         let[i] = '"';
         break;

       case 'q':
         let[i] = '$';
         break;
       case '$':
         let[i] = 'q';
         break;

       case 'z':
         let[i] = '%';
         break;
       case '%':
         let[i] = 'z';
         break;

       case '&':
         let[i] = 'i';
         break;
       case 'i':
         let[i] = '&';
         break;

       case 39:
         let[i] = 'a';
         break;
       case 'a':
         let[i] = 39;
         break;

       case '(':
         let[i] = 'J';
         break;
       case 'J':
         let[i] = '(';
         break;

       case ')':
         let[i] = 'C';
         break;
       case 'C':
         let[i] = ')';
         break;

       case '*':
         let[i] = '3';
         break;
       case '3':
         let[i] = '*';
         break;

       case '+':
         let[i] = ';';
         break;
       case ';':
         let[i] = '+';
         break;

       case ',':
         let[i] = ']';
         break;
       case ']':
         let[i] = ',';
         break;

       case '-':
         let[i] = '/';
         break;
       case '/':
         let[i] = '-';
         break;

       case '.':
         let[i] = '6';
         break;
       case '6':
         let[i] = '.';
         break;

       case '0':
         let[i] = '9';
         break;
       case '9':
         let[i] = '0';
         break;

       case '4':
         let[i] = 'T';
         break;
       case 'T':
         let[i] = '4';
         break;

       case '5':
         let[i] = 'W';
         break;
       case 'W':
         let[i] = '5';
         break;

       case '7':
         let[i] = 'O';
         break;
       case 'O':
         let[i] = '7';
         break;

       case '8':
         let[i] = 'w';
         break;
       case 'w':
         let[i] = '8';
         break;

       case ':':
         let[i] = 'Y';
         break;
       case 'Y':
         let[i] = ':';
         break;

       case '<':
         let[i] = 'y';
         break;
       case 'y':
         let[i] = '<';
         break;

       case '=':
         let[i] = 92;
         break;
       case 92:
         let[i] = '=';
         break;

       case '>':
         let[i] = '_';
         break;
       case '_':
         let[i] = '>';
         break;

       case '?':
         let[i] = '^';
         break;
       case '^':
         let[i] = '?';
         break;

       case '@':
         let[i] = '`';
         break;
       case '`':
         let[i] = '@';
         break;

     case 'B':
       let[i] = 'e';
       break;
     case 'e':
       let[i] = 'B';
       break;

     case 'D':
       let[i] = 'c';
       break;
     case 'c':
       let[i] = 'D';
       break;

     case 'E':
       let[i] = '~';
       break;
     case '~':
       let[i] = 'E';
       break;

     case 'F':
       let[i] = 'n';
       break;
     case 'n':
       let[i] = 'F';
       break;

     case 'G':
       let[i] = 'j';
       break;
     case 'j':
       let[i] = 'G';
       break;

     case 'H':
       let[i] = 'b';
       break;
     case 'b':
       let[i] = 'H';
       break;

     case 'I':
       let[i] = '}';
       break;
     case '}':
       let[i] = 'I';
       break;

     case 'K':
       let[i] = 'g';
       break;
     case 'g':
       let[i] = 'K';
       break;

     case 'L':
       let[i] = 'S';
       break;
     case 'S':
       let[i] = 'L';
       break;

     case 'M':
       let[i] = 'N';
       break;
     case 'N':
       let[i] = 'M';
       break;

     case 'P':
       let[i] = 'U';
       break;
     case 'U':
       let[i] = 'P';
       break;

     case 'Q':
       let[i] = 'u';
       break;
     case 'u':
       let[i] = 'Q';
       break;

     case 'R':
       let[i] = 'p';
       break;
     case 'p':
       let[i] = 'R';
       break;

     case 'V':
       let[i] = 'v';
       break;
     case 'v':
       let[i] = 'V';
       break;

     case 'X':
       let[i] = '|';
       break;
     case '|':
       let[i] = 'X';
       break;

     case '[':
       let[i] = '{';
       break;
     case '{':
       let[i] = '[';
       break;

     case 'd':
       let[i] = 'h';
       break;
     case 'h':
       let[i] = 'd';
       break;

     case 'f':
       let[i] = 'k';
       break;
     case 'k':
       let[i] = 'f';
       break;

     case 'm':
       let[i] = 's';
       break;
     case 's':
       let[i] = 'm';
       break;

     case 'o':
       let[i] = 'r';
       break;
     case 'r':
       let[i] = 'o';
       break;

     case 't':
       let[i] = 'x';
       break;
     case 'x':
       let[i] = 't';
       break;

       }
     }

       String NewS = "";

       for(int d = 0; d < let.length; d++){
         NewS+=let[d];
       }

       out.setText(NewS);


  }
}

Hi everyone,

Set the closing default constant of the frames to hide and set the visibility to false for the frames to be closed by buttons. See the java JFrame api and java JFrame tutorials for more details

Yours Sincerely

Richard West

freesoft_2000, THANK YOU SO MUCH - it worked!

server_crash, how'd the SATs go?

server_crash, how'd the SATs go?

It went ok, I did well on the math and the new essay part, but the reading wasn't so friendly to me..Thanks for asking!

This article has been dead for over six months. Start a new discussion instead.