import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.ActionListener; import java.util.ArrayList; public class Application implements ActionListener { /** * @param args */ private JFrame frame; private JMenuBar menuBar; private JDesktopPane desktop; private ArrayList viewList; public Application() { //Set up the GUI Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame = new JFrame("Ritprogrammet"); createMenu(); frame.setBounds(50,50,screenSize.width/2,screenSize.height/2); frame.setVisible(true); desktop = new JDesktopPane(); frame.setContentPane(desktop); //Attach the internalframe desktop to the Pane //Make dragging a little faster but perhaps uglier. desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); } private void createMenu() { menuBar = new JMenuBar(); JMenu file = new JMenu("File"); menuBar.add(file); JMenuItem view = new JMenuItem("Add view"); view.addActionListener(this); view.setActionCommand("new"); file.add(view); JMenu tools = new JMenu("Tools"); menuBar.add(tools); JMenuItem pen = new JMenuItem("Pen"); tools.add(pen); JMenuItem eraser = new JMenuItem("Eraser"); tools.add(eraser); frame.setJMenuBar(menuBar); frame.pack(); } public void createView() { View newView = new View(); newView.setVisible(true); desktop.add(newView); System.out.println("view created!"); } public void actionPerformed(ActionEvent event) { if("new".equals(event.getActionCommand())) { createView(); } } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); new Application(); } } ################################################################################################# /*View-klassen som representerar en vy * i ritfönstret. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class View extends JInternalFrame { private JInternalFrame window; static int openFrameCount = 0; public View() { window = new JInternalFrame("View #" + (++openFrameCount),true,true,true,true); window.setSize(new Dimension(50,50)); window.setVisible(true); window.pack(); } }