************************************************************************************************ import javax.swing.*; import java.util.*; import java.awt.event.*; import java.awt.*; import javax.imageio.*; import java.io.*; import javax.swing.*; import java.util.ArrayList; public class windowOps { // class variables static Dimension screenSize; private static void getScreenSize() { Toolkit toolkit = Toolkit.getDefaultToolkit(); screenSize = toolkit.getScreenSize(); } private static int getFirstHeight() { getScreenSize(); double height = screenSize.getHeight() * 0.75; Double realHeight = new Double(height); return realHeight.intValue(); } private static int getFirstWidth() { getScreenSize(); double width = screenSize.getWidth() * 0.75; Double realWidth = new Double(width); return realWidth.intValue(); } public void drawFirstWindow() { Data myData = new Data(); infoPanel info = new infoPanel(myData); mapPanel map = new mapPanel(myData, info); myData.openMap(); JScrollPane mapPane = new JScrollPane(map); pilotMenu menu = new pilotMenu(myData); FirstWindow first = new FirstWindow(); first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); first.setSize(getFirstWidth(), getFirstHeight()); first.setLocationRelativeTo(null); first.setTitle("Pilot Plot"); first.setLayout(new BorderLayout()); first.add(mapPane, BorderLayout.CENTER); first.add(menu, BorderLayout.NORTH); first.add(info, BorderLayout.SOUTH); first.setVisible(true); } } class mapPanel extends JPanel { Image map; String filename; public int tempX, tempY, tempX2, tempY2; MyPoint point0, point1; Data myData; infoPanel updater; mapPanel(final Data myData, final infoPanel updater) { this.updater = updater; this.myData = myData; addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { tempX = e.getX(); tempY = e.getY(); myData.list.add(new MyPoint(tempX, tempY, myData.color)); myData.clickCount++; repaint(); updater.updateDisplay(); } }); } protected void paintComponent(Graphics g) { super.paintComponent(g); setPreferredSize(new Dimension(myData.width, myData.height)); g.drawImage(myData.map, 0, 0, myData.width, myData.height, null); // draw the map if (myData.clickCount > 1) { for (int i=1;iThank you for using Pilot Plot v0.1!
" + "To use this program, Open a Map file, draw your route
" + "and either use your information or save it until later.
"); } } class infoPanel extends JPanel{ Data myData; JLabel colorLabel, routeSegs, currentMap, currentRoute; String color; infoPanel(final Data myData) { this.myData = myData; setLayout(new BorderLayout()); // set layout manager // working map panel JPanel workingMap = new JPanel(); workingMap.setLayout(new GridLayout(3,0)); currentMap = new JLabel("
The current working map is: " + myData.filename, JLabel.CENTER); workingMap.add(currentMap); currentRoute = new JLabel("The current working route is: " + myData.routename, JLabel.CENTER); workingMap.add(currentRoute); add(workingMap, BorderLayout.NORTH); // everything but the top panel JPanel everythingElse = new JPanel(); //the clear button JButton clear = new JButton("Clear Route.
Press and then click the map. "); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myData.list.clear(); myData.clickCount=0; } }); everythingElse.setLayout(new GridLayout(0,3,10,10)); routeSegs = new JLabel("The current number of route segments is:
" + "Not implemented yet :P
" + "For a grand total of:
" + "not yet :P" + "nautical miles.", JLabel.CENTER); everythingElse.add(routeSegs); everythingElse.add(new JLabel("If you were to click RIGHT THE FUCK NOW
you would have" + " a route segment of
" + "NOT YET!!
" + "nautical miles", JLabel.CENTER)); //subpanel for the right JPanel right = new JPanel(); right.setLayout(new GridLayout(3,0)); right.add(new JSlider()); right.add(clear); switch (myData.color) { case 0: color = "red"; break; case 1: color = "blue"; break; case 2: color = "green"; break; default: color = "red"; break; } colorLabel = new JLabel("Current color is " + color); right.add(colorLabel); everythingElse.add(right); add(everythingElse, BorderLayout.SOUTH); } public void updateDisplay() { switch (myData.color) { case 0: color = "red"; break; case 1: color = "blue"; break; case 2: color = "green"; break; default: color = "red"; break; } colorLabel.setText("Current color is " + color); routeSegs.setText("The current number of route segments is:
" + (myData.list.size() - 1) + "
" + "For a grand total of:
" + "not yet :P" + "nautical miles."); currentMap.setText("
The current working map is: " + myData.filename); currentRoute.setText("The current working route is: " + myData.routename); } } class MyPoint { int x; int y; int color; MyPoint (int inx, int iny, int incolor) { x=inx; y=iny; color=incolor; } public int getX() { return x; } public int getY() { return y; } public int getColor() { return color; } } *************************************************************************** Data.java import java.util.ArrayList; import javax.imageio.*; import javax.swing.*; import java.awt.*; import java.io.*; public class Data { int clickCount = 0; ArrayList list = new ArrayList(0); int color = 0; //0=red,1=blue,2=green String filename="", newfilename="",routename="New Route"; Image map; int width, height, fullwidth, fullheight, wwidth, wheight; //pic variables public void openMap() { JOptionPane.showMessageDialog(null, "Please load a map file."); JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.showOpenDialog(null); File inFile = fc.getSelectedFile(); filename = inFile.getAbsolutePath(); try { map = ImageIO.read (inFile); } catch (IOException e) { JOptionPane.showMessageDialog(null, "ERROR:\n Could not load map image"); map = null; return; } fullwidth = width = map.getWidth(null); fullheight = height = map.getHeight(null); clickCount = 0; list.clear(); routename="New Route"; } }