Results 1 to 3 of 3
  1. #1
    Tastosis is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default Open next class help

    I have 3 classes, 1 is the main. Initially, the main class calls the first class. How do I change the program so that when I click the "Change to Java Converter" JMenuItem, it calls / opens the second class and closes the first?

    Main:
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class converter {
    
    public static void main(String[] args) {
            JFrame win = new Gui2();
            JMenuBar menubar = new JMenuBar();
    
            JMenu menu = new JMenu("File");
            menubar.add(menu);
            JMenu menu2 = new JMenu("Help");
            menubar.add(menu2);
    
            JMenuItem change = new JMenuItem("Change to Java Converter");
            change.addActionListener(new ActionListener(){
            	public void actionPerformed(ActionEvent e){
            		JFrame win2 = new Gui4();
            	}
            });
            menu.add(change);
    
        	JMenuItem exit = new JMenuItem("Exit");
        	exit.addActionListener(new ActionListener(){
        		public void actionPerformed(ActionEvent e){
        			System.exit(0);
        		}
        	});
        	menu.add(exit);
    
        	JMenuItem about = new JMenuItem("About LTS Converter");
        	about.addActionListener(new ActionListener(){
        		public void actionPerformed(ActionEvent e){
    
        		}
        	});
        	menu2.add(about);
    
        	win.setJMenuBar(menubar);
            win.setVisible(true);
        }
    }
    Class #1:
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    
    public class Gui2 extends JFrame {
    
        private JButton button;
        private JTextArea area;
        private JTextArea area2;
        private JScrollPane scroll;
        private JScrollPane scroll2;
        private JSplitPane splitPane;
        private JPanel forbutton;
        private JPanel content;
    
        public Gui2() {
            initComponents();
        }
    
        private void initComponents() {
    
            button = new JButton("CONVERT");
    
            forbutton = new JPanel();
            forbutton.add(button);
    
            area = new JTextArea(40, 45);
            area2 = new JTextArea(40, 45);
    
            scroll = new JScrollPane(area);
            add(scroll);
    
            scroll2 = new JScrollPane(area2);
            add(scroll2);
    
            splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, area, area2);
            splitPane.setOneTouchExpandable(false);
            splitPane.setResizeWeight(0.5);
    
            content = new JPanel();
            content.setLayout(new BorderLayout());
            content.add(splitPane, BorderLayout.CENTER);
            content.add(forbutton, BorderLayout.PAGE_END);
    
            setContentPane(content);
            setTitle("LTS Converter");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
    
            HandlerClass handler = new HandlerClass();
            button.addActionListener(handler);
        }
    
        private class HandlerClass implements ActionListener {
    
            public void actionPerformed(ActionEvent event) {
            	String one = "printf";
            	String two = "scanf";
            	String three = "int";
            	String four = "float";
            	String five = "double";
            	String six = "include";
            	String seven = "char";
            	String eight = "String";
            	String nine = "main";
            	String ten = "return";
            	String _11 = "for";
            	String _12 = "do";
            	String _13 = "while";
            	String _14 = "public";
            	String _15 = "void";
    
            	String a = "imprimaref";
            	String b = "scanaref";
            	String c = "intreg";
            	String d = "pluti";
            	String e = "dublu";
            	String f = "inchide";
            	String g = "caracter";
            	String h = "serie";
            	String i = "uscat";
            	String j = "intoarcere";
            	String k = "pentru";
            	String l = "nu";
            	String m = "rastimp";
            	String n = "publice";
            	String o = "gol";
    
            	String code = area.getText();
    
            	String code2 = code.replace(one, a);
            	String code3 = code2.replace(two, b);
            	String code4 = code3.replace(three, c);
            	String code5 = code4.replace(four, d);
            	String code6 = code5.replace(five, e);
            	String code7 = code6.replace(six, f);
            	String code8 = code7.replace(seven, g);
            	String code9 = code8.replace(eight, h);
            	String code10 = code9.replace(nine, i);
            	String code11 = code10.replace(ten, j);
            	String code12 = code9.replace(_11, k);
            	String code13 = code9.replace(_12, l);
            	String code14 = code9.replace(_13, m);
            	String code15 = code9.replace(_14, n);
            	String code_final = code15.replace(_15, o);
    
            	area2.setText(code_final);
            }
    	}
    }
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    
    public class Gui4 extends JFrame {
    
        private JButton button;
        private JTextArea area;
        private JTextArea area2;
        private JScrollPane scroll;
        private JScrollPane scroll2;
        private JSplitPane splitPane;
        private JPanel forbutton;
        private JPanel content;
    
        public Gui4() {
            initComponents();
        }
    
        private void initComponents() {
    
            button = new JButton("CONVERT");
    
            forbutton = new JPanel();
            forbutton.add(button);
    
            area = new JTextArea(40, 45);
            area2 = new JTextArea(40, 45);
    
            scroll = new JScrollPane(area);
            add(scroll);
    
            scroll2 = new JScrollPane(area2);
            add(scroll2);
    
            splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, area, area2);
            splitPane.setOneTouchExpandable(false);
            splitPane.setResizeWeight(0.5);
    
            content = new JPanel();
            content.setLayout(new BorderLayout());
            content.add(splitPane, BorderLayout.CENTER);
            content.add(forbutton, BorderLayout.PAGE_END);
    
            setContentPane(content);
            setTitle("LTS Converter");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
    
            HandlerClass handler = new HandlerClass();
            button.addActionListener(handler);
        }
    
        private class HandlerClass implements ActionListener {
    
            public void actionPerformed(ActionEvent event) {
            	String one = "printf";
            	String two = "scanf";
            	String three = "int";
            	String four = "float";
            	String five = "double";
            	String six = "include";
            	String seven = "char";
            	String eight = "String";
            	String nine = "main";
            	String ten = "return";
            	String _11 = "for";
            	String _12 = "do";
            	String _13 = "while";
            	String _14 = "public";
            	String _15 = "void";
    
            	String a = "imprimaref";
            	String b = "scanaref";
            	String c = "intreg";
            	String d = "pluti";
            	String e = "dublu";
            	String f = "inchide";
            	String g = "caracter";
            	String h = "serie";
            	String i = "uscat";
            	String j = "intoarcere";
            	String k = "pentru";
            	String l = "nu";
            	String m = "rastimp";
            	String n = "publice";
            	String o = "gol";
    
            	String code = area.getText();
    
            	String code2 = code.replace(one, a);
            	String code3 = code2.replace(two, b);
            	String code4 = code3.replace(three, c);
            	String code5 = code4.replace(four, d);
            	String code6 = code5.replace(five, e);
            	String code7 = code6.replace(six, f);
            	String code8 = code7.replace(seven, g);
            	String code9 = code8.replace(eight, h);
            	String code10 = code9.replace(nine, i);
            	String code_final = code10.replace(ten, j);
    
            	area2.setText(code_final);
            }
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    What do you mean by "open" and "closing" a class? Are you talking about setting the visibility of JFrames? (that was more a hint than a question)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Tastosis is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 02-07-2011, 08:43 AM
  2. Project does not open
    By rogernem in forum NetBeans
    Replies: 7
    Last Post: 06-30-2010, 11:11 AM
  3. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 02:14 PM
  4. How do I open a file with a class, or can I?
    By bobleny in forum New To Java
    Replies: 4
    Last Post: 04-02-2009, 09:59 AM
  5. Replies: 4
    Last Post: 02-16-2009, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •