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; String color; infoPanel(final Data myData) { this.myData = myData; setLayout(new BorderLayout()); JPanel workingMap = new JPanel(); workingMap.setLayout(new GridLayout(3,0)); workingMap.add(new JLabel("
The current working map is: " + myData.filename, JLabel.CENTER)); workingMap.add(new JLabel("The current working route is: " + myData.routename, JLabel.CENTER)); add(workingMap, BorderLayout.NORTH); JPanel everythingElse = new JPanel(); 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)); everythingElse.add(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(new JLabel("If you were to click RIGHT THE FUCK NOW
you would have" + " a route segment of
" + "NOT YET!!
" + "nautical miles", JLabel.CENTER)); 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); } } 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; } }