I want to have my program in three classes according to the MCV-model. The problem is that I cannot manage to do it right, cause it won't start and other things. This is the code when it is NOT in MVC:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.Random; public class Class1 extends JFrame implements ActionListener { private JMenuItem fMenuOpen; private JMenuItem fMenuSave; private JMenuItem fMenuClose; private JMenuItem fMenuRandom; private JMenuItem fMenuClear; private JTextArea textruta; File theFile = new File ("*.java"); public Class1 (String title) { super(title); Container content_pane = getContentPane(); content_pane.setLayout (new BorderLayout()); textruta = new JTextArea(); JMenu downMenu = new JMenu ("Arkiv"); content_pane.add(textruta); downMenu.add(fMenuRandom = createMenuItem("Random numbers")); downMenu.add(fMenuClear = createMenuItem("Clear")); downMenu.add(fMenuSave = createMenuItem("Save")); downMenu.add(fMenuOpen = createMenuItem("Open")); downMenu.addSeparator(); downMenu.add(fMenuClose = createMenuItem("Quit")); JMenuBar menuBar = new JMenuBar(); menuBar.add (downMenu); setJMenuBar (menuBar); setSize (250, 250); setLocation(400, 100); } private JMenuItem createMenuItem(String name) { JMenuItem m = new JMenuItem(name); m.addActionListener(this); return m; } public void actionPerformed (ActionEvent e) { boolean status = false; String command = e.getActionCommand(); if (command.equals("Clear")){ textruta.setText(null); } if (command.equals("Random numbers")){ Random randomNr = new Random(); int tal; for (int i = 0; i < 7; i++) { tal = randomNr.nextInt(35); textruta.append(tal + " "); } } if (command.equals ("Open")) { status = openFile (); } else if (command.equals ("Save")) { status = saveFile (); } else if (command.equals ("Quit") ) { System.exit(1); } } boolean openFile () { JFileChooser fc = new JFileChooser(); fc.setDialogTitle ("Open file"); int result = fc.showOpenDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return true; } else if (result == JFileChooser.APPROVE_OPTION) { theFile = fc.getSelectedFile(); String file_string = readFile (theFile); if (file_string != null) textruta.setText (file_string); else return false; } return true; } boolean saveFile() { File file = null; JFileChooser fc = new JFileChooser(); fc.setSelectedFile (theFile); int result = fc.showSaveDialog (this); if (result == JFileChooser.CANCEL_OPTION) { return true; } else if (result == JFileChooser.APPROVE_OPTION) { theFile = fc.getSelectedFile(); return writeFile (theFile, textruta.getText()); } else { return false; } } public String readFile (File file) { StringBuffer fileBuffer; String fileString = null; String line; try { FileReader in = new FileReader (file); BufferedReader dis = new BufferedReader(in); fileBuffer = new StringBuffer() ; while ((line = dis.readLine()) != null) { fileBuffer.append(line + "\n"); } in.close(); fileString = fileBuffer.toString(); } catch(IOException e) { return null; } return fileString; } public static boolean writeFile(File file, String dataString) { try { PrintWriter out = new PrintWriter(new BufferedWriter (new FileWriter (file))); out.print(dataString); out.flush(); out.close(); } catch (IOException e) { return false; } return true; } public static void main(String [] args) { String title = "Lotto"; Class1 f = new Class1 (title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }