public void init() { // <Begin_init> if (initialized == true) return; this.setSize(getPreferredSize().width + 682, getPreferredSize().height + 419); setTitle(NmsClientUtil.GetString("Router Display Panel")); Container container = getContentPane(); container.setLayout(new BorderLayout()); try { initVariables(); setUpGUI(container); setUpProperties(); setUpConnections(); } catch (Exception ex) { showStatus(NmsClientUtil.GetString("Error in init method"), ex); } // let us set the initialzed variable to true so // we dont initialize again even if init is called initialized = true; setUpMenus(); setUpToolBar(); // <End_init> setIconImage(NmsClientUtil.getFrameIcon()); }
public GLDemo() { super(VNMRFrame.getVNMRFrame(), "Jogl Demo", false); DisplayOptions.addChangeListener(this); contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); gradientPanel = createGradientPanel(); contentPane.add(gradientPanel, BorderLayout.CENTER); checkBox = new JCheckBox("Transparent", true); checkBox.setActionCommand("transparancy"); checkBox.addActionListener(this); optionsPan = new JPanel(); optionsPan.setLayout(new SimpleH2Layout(SimpleH2Layout.LEFT, 5, 0, true, false)); optionsPan.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); optionsPan.add(checkBox); runButton = new JToggleButton("Run"); runButton.setActionCommand("run"); runButton.setSelected(false); runButton.addActionListener(this); optionsPan.add(runButton); getContentPane().add(optionsPan, BorderLayout.SOUTH); setSize(300, 300); setLocation(300, 300); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { // Run this on another thread than the AWT event queue to // make sure the call to Animator.stop() completes before // exiting new Thread( new Runnable() { public void run() { stop(); } }) .start(); } }); setVisible(false); }
/** * @param filenames * @exception Exception if internal error */ public ChestImageViewer(String filenames[]) throws Exception { DisplayDeviceArea[] displayDeviceAreas = getPresentationAndImageDeviceAreas(); if (displayDeviceAreas == null) { System.err.println("Cannot determine device display areas"); } else { System.err.println("Found " + displayDeviceAreas.length + " device display areas"); for (int i = 0; i < displayDeviceAreas.length; ++i) { System.err.println("[" + i + "] = " + displayDeviceAreas[i]); displayDeviceAreas[i].getFrame().setBackground(Color.black); displayDeviceAreas[i].getFrame().setVisible(true); } { // Need to actually add something to the unused left display frame, else background will not // be set to black on Windows JPanel backgroundPanel = new JPanel(); backgroundPanel.setBackground(Color.black); displayDeviceAreas[0].getFrame().getContentPane().add(backgroundPanel); displayDeviceAreas[0].getFrame().validate(); } frame = displayDeviceAreas[1].getFrame(); Container content = frame.getContentPane(); content.setLayout(new GridLayout(1, 1)); multiPanel = new JPanel(); // multiPanel.setBackground(Color.black); frameWidth = (int) frame.getWidth(); frameHeight = (int) frame.getHeight(); Dimension d = new Dimension(frameWidth, frameHeight); // multiPanel.setSize(d); multiPanel.setPreferredSize(d); multiPanel.setBackground(Color.black); content.add(multiPanel); // frame.pack(); content.validate(); loadMultiPanelFromSpecifiedFiles(filenames); } }
/** * Standard constructor: it needs the parent frame. * * @param parent the dialog's parent */ public DialogPrint(JFrame parent) { super(400, 350, parent, Globals.messages.getString("Print_dlg"), true); addComponentListener(this); export = false; // Ensure that under MacOSX >= 10.5 Leopard, this dialog will appear // as a document modal sheet getRootPane().putClientProperty("apple.awt.documentModalSheet", Boolean.TRUE); GridBagLayout bgl = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); Container contentPane = getContentPane(); contentPane.setLayout(bgl); constraints.insets.right = 30; JLabel empty = new JLabel(" "); constraints.weightx = 100; constraints.weighty = 100; constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = 1; contentPane.add(empty, constraints); // Add " " label JLabel empty1 = new JLabel(" "); constraints.weightx = 100; constraints.weighty = 100; constraints.gridx = 3; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = 1; contentPane.add(empty1, constraints); // Add " " label mirror_CB = new JCheckBox(Globals.messages.getString("Mirror")); constraints.gridx = 1; constraints.gridy = 0; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(mirror_CB, constraints); // Add Print Mirror cb fit_CB = new JCheckBox(Globals.messages.getString("FitPage")); constraints.gridx = 1; constraints.gridy = 1; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(fit_CB, constraints); // Add Fit to page cb bw_CB = new JCheckBox(Globals.messages.getString("B_W")); constraints.gridx = 1; constraints.gridy = 2; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(bw_CB, constraints); // Add BlackWhite cb landscape_CB = new JCheckBox(Globals.messages.getString("Landscape")); constraints.gridx = 1; constraints.gridy = 3; constraints.gridwidth = 2; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.WEST; contentPane.add(landscape_CB, constraints); // Add landscape cb // Put the OK and Cancel buttons and make them active. JButton ok = new JButton(Globals.messages.getString("Ok_btn")); JButton cancel = new JButton(Globals.messages.getString("Cancel_btn")); constraints.gridx = 0; constraints.gridy = 4; constraints.gridwidth = 4; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.EAST; // Put the OK and Cancel buttons and make them active. Box b = Box.createHorizontalBox(); b.add(Box.createHorizontalGlue()); ok.setPreferredSize(cancel.getPreferredSize()); if (Globals.okCancelWinOrder) { b.add(ok); b.add(Box.createHorizontalStrut(12)); b.add(cancel); } else { b.add(cancel); b.add(Box.createHorizontalStrut(12)); b.add(ok); } ok.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { export = true; setVisible(false); } }); cancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { setVisible(false); } }); // Here is an action in which the dialog is closed AbstractAction cancelAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { setVisible(false); } }; contentPane.add(b, constraints); // Add OK/cancel dialog DialogUtil.addCancelEscape(this, cancelAction); pack(); DialogUtil.center(this); getRootPane().setDefaultButton(ok); }
/** @param arg */ public static void main(String arg[]) { TestApp af = new TestApp(); SourceImage sImg = null; int imagesPerRow = 0; int imagesPerCol = 0; int imgMin = 65536; int imgMax = 0; boolean signed = false; boolean inverted = false; boolean hasPad = false; int padValue = 0; if (arg.length == 6) { // do it with raw file int w = 0; int h = 0; int d = 0; try { w = Integer.valueOf(arg[1]).intValue(); h = Integer.valueOf(arg[2]).intValue(); d = Integer.valueOf(arg[3]).intValue(); imagesPerRow = Integer.valueOf(arg[4]).intValue(); imagesPerCol = Integer.valueOf(arg[5]).intValue(); } catch (Exception e) { System.err.println(e); System.exit(0); } try { FileInputStream i = new FileInputStream(arg[0]); sImg = new SourceImage(i, w, h, d); } catch (Exception e) { System.err.println(e); System.exit(0); } } else { // do it with DICOM file if (arg.length > 2) { try { imagesPerRow = Integer.valueOf(arg[1]).intValue(); imagesPerCol = Integer.valueOf(arg[2]).intValue(); } catch (Exception e) { System.err.println(e); e.printStackTrace(System.err); System.exit(0); } } else { imagesPerRow = 1; imagesPerCol = 1; } try { DicomInputStream i = new DicomInputStream(new FileInputStream(arg[0])); sImg = new SourceImage(i); } catch (Exception e) { System.err.println(e); e.printStackTrace(System.err); System.exit(0); } } try { // com.apple.cocoa.application.NSMenu.setMenuBarVisible(false); // Won't compile on // other platforms // Class classToUse = // ClassLoader.getSystemClassLoader().loadClass("com.apple.cocoa.application.NSMenu"); // // Needs "/System/Library/Java" in classpath Class classToUse = new java.net.URLClassLoader(new java.net.URL[] {new File("/System/Library/Java").toURL()}) .loadClass("com.apple.cocoa.application.NSMenu"); Class[] parameterTypes = {Boolean.TYPE}; java.lang.reflect.Method methodToUse = classToUse.getDeclaredMethod("setMenuBarVisible", parameterTypes); Object[] args = {Boolean.FALSE}; methodToUse.invoke(null /*since static*/, args); } catch (Exception e) { // ClassNotFoundException,NoSuchMethodException,IllegalAccessException e.printStackTrace(System.err); } java.awt.Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); int frameWidth = (int) d.getWidth(); int frameHeight = (int) d.getHeight(); System.err.println("frameWidth=" + frameWidth); System.err.println("frameHeight=" + frameHeight); af.setUndecorated(true); af.setLocation(0, 0); af.setSize(frameWidth, frameHeight); JPanel multiPanel = new JPanel(); multiPanel.setLayout(new GridLayout(imagesPerCol, imagesPerRow)); multiPanel.setBackground(Color.black); SingleImagePanel imagePanel[] = new SingleImagePanel[imagesPerRow * imagesPerCol]; int singleWidth = frameWidth / imagesPerRow; int singleHeight = frameHeight / imagesPerCol; System.err.println("singleWidth=" + singleWidth); System.err.println("singleHeight=" + singleHeight); for (int x = 0; x < imagesPerCol; ++x) { for (int y = 0; y < imagesPerRow; ++y) { SingleImagePanel ip = new SingleImagePanel(sImg); // ip.setPreferredSize(new Dimension(img.getWidth(),img.getHeight())); // ip.setPreferredSize(new Dimension(sImg.getWidth(),sImg.getHeight())); ip.setPreferredSize(new Dimension(singleWidth, singleHeight)); multiPanel.add(ip); imagePanel[x * imagesPerRow + y] = ip; } } // multiPanel.setSize(img.getWidth()*imagesPerRow,img.getHeight()*imagesPerRow); // JScrollPane scrollPane = new JScrollPane(multiPanel); Container content = af.getContentPane(); content.setLayout(new GridLayout(1, 1)); // content.add(scrollPane); content.add(multiPanel); af.pack(); af.setVisible(true); }
/** *********** Initialization of every component and variable being used ************* */ IPToolKit() { cp = new Container(); cp.setLayout(new BorderLayout()); Main_pnl = new JPanel(); jmb = new JMenuBar(); m_File = new JMenu("File"); m_Arith = new JMenu("Arithmetic"); m_Filter = new JMenu("Filters"); m_Open = new JMenuItem("Open"); m_Save = new JMenuItem("Save"); m_Exit = new JMenuItem("Exit"); m_Add = new JMenu("Add"); m_Sub = new JMenu("Subtract"); m_Mul = new JMenu("Multiply"); m_Div = new JMenu("Divide"); edge = new JMenu("Edge Detection"); mpre = new JMenu("Prewits"); msob = new JMenu("Sobel"); lbl_img = new JLabel(""); lbl_gray = new JLabel(""); lbl_res = new JLabel(""); jfc = new JFileChooser(); panel_image = new JPanel(); panel_gray = new JPanel(); panel_result = new JPanel(); scrollPane = new JScrollPane(); mAddConst = new JMenu("Constant"); mSubConst = new JMenu("Constant"); mMulConst = new JMenu("Constant"); mDivConst = new JMenu("Constant"); mAddSat = new JMenuItem("Saturation"); mAddWrap = new JMenuItem("Wrap Around"); mSubSat = new JMenuItem("Saturation"); mSubWrap = new JMenuItem("Wrap Around"); mMulSat = new JMenuItem("Saturation"); mMulWrap = new JMenuItem("Wrap Around"); mDivSat = new JMenuItem("Saturation"); mDivWrap = new JMenuItem("Wrap Around"); mAddImg = new JMenuItem("Image"); mSubImg = new JMenuItem("Image"); mMulImg = new JMenuItem("Image"); mDivImg = new JMenuItem("Image"); mlowPass = new JMenuItem("Low Pass"); mhighPass = new JMenuItem("High Pass"); mhighBoost = new JMenuItem("High Boost"); median = new JMenuItem("Median"); mBright = new JMenuItem("Brightness"); mContrast = new JMenuItem("Contrast Stretch"); mThreshold = new JMenuItem(" Threshold "); m_Enhance = new JMenu("Enhancement"); mInvert = new JMenuItem("Negative"); mpre_hor = new JMenuItem("Prewits Horizontal"); mpre_ver = new JMenuItem("Prewits Vertical"); mpre_both = new JMenuItem("Prewits Both"); msob_hor = new JMenuItem("Sobel Horizontal"); msob_ver = new JMenuItem("Sobel Vertical"); msob_both = new JMenuItem("Sobel Both"); ; mrob = new JMenuItem("Roberts"); mean = new JMenuItem("Mean"); mlap = new JMenuItem("Laplacian"); other = new JMenu("Other"); hist = new JMenuItem("Histogram Equalization"); conect = new JMenuItem("Connected Component"); mBlend = new JMenuItem("Blending"); vsb = new JScrollBar(JScrollBar.VERTICAL); hsb = new JScrollBar(JScrollBar.HORIZONTAL); // jsp = new JScrollPane(); setJMenuBar(jmb); add(cp); // setBackground(new Color(255,255,255)); panel_image.setBackground(new Color(255, 0, 0)); panel_gray.setBackground(new Color(0, 255, 0)); panel_result.setBackground(new Color(0, 0, 255)); jmb.add(m_File); jmb.add(m_Arith); jmb.add(m_Enhance); jmb.add(m_Filter); jmb.add(edge); jmb.add(other); cp.add(Main_pnl); Main_pnl.setLayout(new GridLayout(1, 3, 10, 10)); Main_pnl.add(panel_image); Main_pnl.add(panel_gray); Main_pnl.add(panel_result); m_File.add(m_Open); m_File.add(m_Save); m_File.add(m_Exit); m_Arith.add(m_Add); m_Add.add(mAddImg); m_Add.add(mAddConst); mAddConst.add(mAddSat); mAddConst.add(mAddWrap); m_Arith.add(m_Sub); m_Sub.add(mSubImg); m_Sub.add(mSubConst); mSubConst.add(mSubSat); mSubConst.add(mSubWrap); m_Arith.add(m_Mul); m_Mul.add(mMulImg); m_Mul.add(mMulConst); mMulConst.add(mMulSat); mMulConst.add(mMulWrap); m_Arith.add(m_Div); m_Div.add(mDivImg); m_Div.add(mDivConst); mDivConst.add(mDivSat); mDivConst.add(mDivWrap); m_Filter.add(mlowPass); m_Filter.add(mhighPass); m_Filter.add(mhighBoost); m_Filter.add(median); m_Filter.add(mean); edge.add(mpre); edge.add(msob); mpre.add(mpre_hor); mpre.add(mpre_ver); mpre.add(mpre_both); msob.add(msob_hor); msob.add(msob_ver); msob.add(msob_both); edge.add(mrob); edge.add(mlap); m_Enhance.add(mBright); m_Enhance.add(mContrast); m_Enhance.add(mThreshold); m_Enhance.add(mInvert); m_Enhance.add(mBlend); other.add(hist); other.add(conect); m_Open.addActionListener(this); m_Save.addActionListener(this); m_Exit.addActionListener(this); mAddImg.addActionListener(this); mSubImg.addActionListener(this); mMulImg.addActionListener(this); mDivImg.addActionListener(this); mAddSat.addActionListener(this); mAddWrap.addActionListener(this); mSubSat.addActionListener(this); mSubWrap.addActionListener(this); mMulSat.addActionListener(this); mMulWrap.addActionListener(this); mDivSat.addActionListener(this); mDivWrap.addActionListener(this); mlowPass.addActionListener(this); mhighPass.addActionListener(this); mhighBoost.addActionListener(this); median.addActionListener(this); mBright.addActionListener(this); mContrast.addActionListener(this); mThreshold.addActionListener(this); mInvert.addActionListener(this); mBlend.addActionListener(this); mpre_hor.addActionListener(this); mpre_ver.addActionListener(this); mpre_both.addActionListener(this); msob_hor.addActionListener(this); msob_ver.addActionListener(this); msob_both.addActionListener(this); mrob.addActionListener(this); mean.addActionListener(this); mlap.addActionListener(this); hist.addActionListener(this); conect.addActionListener(this); lbl_gray.addMouseListener(this); panel_image.add(lbl_img); panel_gray.add(lbl_gray); panel_result.add(lbl_res); cp.add(vsb, BorderLayout.EAST); cp.add(hsb, BorderLayout.SOUTH); // cp1 = getContentPane(); cp = getContentPane(); setSize(600, 400); setVisible(true); }
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner non-commercial license dialogPane = new JPanel(); contentPanel = new JPanel(); panel1 = new JPanel(); label2 = new JLabel(); ttfSizeW = new JTextField(); label4 = new JLabel(); ttfLongi = new JTextField(); btnGetMap = new JButton(); label3 = new JLabel(); ttfSizeH = new JTextField(); label5 = new JLabel(); ttfLati = new JTextField(); btnQuit = new JButton(); label1 = new JLabel(); ttfLicense = new JTextField(); label6 = new JLabel(); ttfZoom = new JTextField(); // ComboBox for Saved Locations ttfSave = new JComboBox(); scrollPane1 = new JScrollPane(); ttaStatus = new JTextArea(); panel2 = new JPanel(); panel3 = new JPanel(); checkboxRecvStatus = new JCheckBox(); checkboxSendStatus = new JCheckBox(); ttfProgressMsg = new JTextField(); progressBar = new JProgressBar(); lblProgressStatus = new JLabel(); // ======== this ======== setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle("Google Static Maps"); setIconImage(null); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); // ======== dialogPane ======== { dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); dialogPane.setOpaque(false); dialogPane.setLayout(new BorderLayout()); // ======== contentPanel ======== { contentPanel.setOpaque(false); contentPanel.setLayout( new TableLayout( new double[][] { {TableLayout.FILL}, {TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED} })); ((TableLayout) contentPanel.getLayout()).setHGap(5); ((TableLayout) contentPanel.getLayout()).setVGap(5); // ======== panel1 ======== { panel1.setOpaque(false); panel1.setBorder( new CompoundBorder( new TitledBorder("Configure the inputs to Google Static Maps"), Borders.DLU2_BORDER)); panel1.setLayout( new TableLayout( new double[][] { {0.17, 0.17, 0.17, 0.17, 0.05, TableLayout.FILL}, {TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED} })); ((TableLayout) panel1.getLayout()).setHGap(5); ((TableLayout) panel1.getLayout()).setVGap(5); // ---- label2 ---- label2.setText("Size Width"); label2.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label2, new TableLayoutConstraints( 0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfSizeW ---- ttfSizeW.setText("512"); panel1.add( ttfSizeW, new TableLayoutConstraints( 1, 0, 1, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label4 ---- label4.setText("Latitude"); label4.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label4, new TableLayoutConstraints( 2, 0, 2, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfLongi ---- ttfLongi.setText("38.931099"); panel1.add( ttfLongi, new TableLayoutConstraints( 3, 0, 3, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- btnGetMap ---- btnGetMap.setText("Get Map"); btnGetMap.setHorizontalAlignment(SwingConstants.LEFT); btnGetMap.setMnemonic('G'); btnGetMap.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { startTaskAction(); if (Integer.parseInt(ttfZoom.getText()) < 14) { // coding for zoom values under 14 for (int i = 0; i < 14; i++) { if (Integer.parseInt(ttfZoom.getText()) == i) { countThis = 14 - i; // gets difference do { counter = counter * 2; // found out code zooms in powers of 2. pixelX = 0.000084525 * counter; // Values per Latitude, trial and error method used to // find these numbers. pixelY = 0.00006725 * counter; // Values per Longitude counter1++; } while (counter1 != countThis); // loops the amount of differences } counter = 1; // Resetters counter1 = 0; } } else if (Integer.parseInt(ttfZoom.getText()) > 14) { // coding for zoom values over 14 for (int i = 14; i < 19; i++) { if (Integer.parseInt(ttfZoom.getText()) == i) { countThis = i - 14; // gets difference do { counter = counter * 2; pixelX = 0.000084525 / counter; // Values per Latitude pixelY = 0.00006725 / counter; // Values per Longitude counter1++; } while (counter1 != countThis); // loops amount of differences } counter = 1; // Resetters counter1 = 0; } } else { // coding for zoom default value of 14. pixelX = 0.000084525; pixelY = 0.00006725; } BigDecimal sendPixelX = new BigDecimal(pixelX); BigDecimal sendPixelY = new BigDecimal(pixelY); pixelX = (sendPixelX.setScale(6, BigDecimal.ROUND_HALF_UP)) .doubleValue(); // allows for bigger decimal zoom variables pixelY = (sendPixelY.setScale(6, BigDecimal.ROUND_HALF_UP)) .doubleValue(); // Won't reach zoom 1-5 without these! } }); panel1.add( btnGetMap, new TableLayoutConstraints( 5, 0, 5, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label3 ---- label3.setText("Size Height"); label3.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label3, new TableLayoutConstraints( 0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfSizeH ---- ttfSizeH.setText("512"); panel1.add( ttfSizeH, new TableLayoutConstraints( 1, 1, 1, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label5 ---- label5.setText("Longitude"); label5.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label5, new TableLayoutConstraints( 2, 1, 2, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfLati ---- ttfLati.setText("-77.3489"); panel1.add( ttfLati, new TableLayoutConstraints( 3, 1, 3, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- btnQuit ---- btnQuit.setText("Quit"); btnQuit.setMnemonic('Q'); btnQuit.setHorizontalAlignment(SwingConstants.LEFT); btnQuit.setHorizontalTextPosition(SwingConstants.RIGHT); btnQuit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { quitProgram(); } }); panel1.add( btnQuit, new TableLayoutConstraints( 5, 1, 5, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label1 ---- label1.setText("License Key"); label1.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label1, new TableLayoutConstraints( 0, 2, 0, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfLicense ---- ttfLicense.setToolTipText("Enter your own URI for a file to download in the background"); panel1.add( ttfLicense, new TableLayoutConstraints( 1, 2, 1, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label6 ---- label6.setText("Zoom"); label6.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label6, new TableLayoutConstraints( 2, 2, 2, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfZoom ---- ttfZoom.setText("14"); panel1.add( ttfZoom, new TableLayoutConstraints( 3, 2, 3, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfSave ---- ttfSave.removeAllItems(); // JComboBox ttfSave = new JComboBox(); getSavedLocations(); // grabs a new list for (int i = 0; i < loc.size(); i++) // populates this list using a arrayList ttfSave.addItem(loc.get(i)); ttfSave.setSelectedIndex(0); panel1.add( ttfSave, new TableLayoutConstraints( 5, 2, 5, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // Action Listener to update the coordinates on selected Location ttfSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (mapIsUp == 0) { Object contents = ttfSave.getSelectedItem(); // grabs users selection System.out.println(contents); if (contents != null) { stringCoords = contents.toString(); setCoords = stringCoords.split("\\s+"); ttfLongi.setText( setCoords[ 1]); // sets the texts in the longitude and latitude fields to // coordinates selected ttfLati.setText(setCoords[0]); } } } }); } contentPanel.add( panel1, new TableLayoutConstraints( 0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ======== scrollPane1 ======== { scrollPane1.setBorder( new TitledBorder("System.out - displays all status and progress messages, etc.")); scrollPane1.setOpaque(false); // ---- ttaStatus ---- ttaStatus.setBorder(Borders.createEmptyBorder("1dlu, 1dlu, 1dlu, 1dlu")); ttaStatus.setToolTipText( "<html>Task progress updates (messages) are displayed here,<br>along with any other output generated by the Task.<html>"); scrollPane1.setViewportView(ttaStatus); } contentPanel.add( scrollPane1, new TableLayoutConstraints( 0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ======== panel2 ======== { panel2.setOpaque(false); panel2.setBorder( new CompoundBorder( new TitledBorder("Status - control progress reporting"), Borders.DLU2_BORDER)); panel2.setLayout( new TableLayout( new double[][] { {0.45, TableLayout.FILL, 0.45}, {TableLayout.PREFERRED, TableLayout.PREFERRED} })); ((TableLayout) panel2.getLayout()).setHGap(5); ((TableLayout) panel2.getLayout()).setVGap(5); // ======== panel3 ======== { panel3.setOpaque(false); panel3.setLayout(new GridLayout(1, 2)); // ---- checkboxRecvStatus ---- checkboxRecvStatus.setText("Enable \"Recieve\""); checkboxRecvStatus.setOpaque(false); checkboxRecvStatus.setToolTipText("Task will fire \"send\" status updates"); checkboxRecvStatus.setSelected(true); panel3.add(checkboxRecvStatus); // ---- checkboxSendStatus ---- checkboxSendStatus.setText("Enable \"Send\""); checkboxSendStatus.setOpaque(false); checkboxSendStatus.setToolTipText("Task will fire \"recieve\" status updates"); panel3.add(checkboxSendStatus); } panel2.add( panel3, new TableLayoutConstraints( 0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfProgressMsg ---- ttfProgressMsg.setText("Loading map from Google Static Maps"); ttfProgressMsg.setToolTipText("Set the task progress message here"); panel2.add( ttfProgressMsg, new TableLayoutConstraints( 2, 0, 2, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- progressBar ---- progressBar.setStringPainted(true); progressBar.setString("progress %"); progressBar.setToolTipText("% progress is displayed here"); panel2.add( progressBar, new TableLayoutConstraints( 0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- lblProgressStatus ---- lblProgressStatus.setText("task status listener"); lblProgressStatus.setHorizontalTextPosition(SwingConstants.LEFT); lblProgressStatus.setHorizontalAlignment(SwingConstants.LEFT); lblProgressStatus.setToolTipText( "Task status messages are displayed here when the task runs"); panel2.add( lblProgressStatus, new TableLayoutConstraints( 2, 1, 2, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); } contentPanel.add( panel2, new TableLayoutConstraints( 0, 2, 0, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); } dialogPane.add(contentPanel, BorderLayout.CENTER); } contentPane.add(dialogPane, BorderLayout.CENTER); setSize(675, 485); setLocationRelativeTo(null); // JFormDesigner - End of component initialization //GEN-END:initComponents }
/** Constructor to set everything up */ public TicTac() { // Set defaults before settings are changed via menus // (defaults are vs AI, play as X, with graphics on) multiPlayers = false; temp = false; currentPlayer = Symbol.X; ai = Symbol.O; difficulty = Difficulty.IMPOSSIBLE; frame = new JFrame("Tic Tac Toe"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // Set preferred size so game fills window nicely this.setPreferredSize(new Dimension(cellSize * ROWS, cellSize * COLS)); frame.add(this); // Load images try { sword = ImageIO.read(new File("swordsBlue.png")); saber = ImageIO.read(new File("saber2.png")); skull = ImageIO.read(new File("skull.png")); ring = ImageIO.read(new File("ring.png")); smiley = ImageIO.read(new File("smiley.png")); hydra = ImageIO.read(new File("hydra.png")); finalfantasy = ImageIO.read(new File("finalfantasy.jpg")); dragon = ImageIO.read(new File("dargon.jpg")); night = ImageIO.read(new File("night.jpg")); } catch (IOException e) { System.out.println("Could not open image files, turning images off!"); useImages = false; } imageX = saber; imageO = ring; background = dragon; // Create menu bars. Each one item will need a listener menuBar = new JMenuBar(); JMenu menu = new JMenu("Mode"); JMenu menu2 = new JMenu("Side"); JMenu menu3 = new JMenu("Graphics"); JMenu menu4 = new JMenu("Other"); JMenu menu5 = new JMenu("Difficulty"); JMenu xImageMenu = new JMenu("Image for X"); JMenu oImageMenu = new JMenu("Image for O"); JMenu backgroundMenu = new JMenu("Set Background"); menuBar.add(menu); menuBar.add(menu2); menuBar.add(menu5); menuBar.add(menu3); menuBar.add(menu4); // Create checkbox menu items for choices final JCheckBoxMenuItem item = new JCheckBoxMenuItem("2 Player"); final JCheckBoxMenuItem item2 = new JCheckBoxMenuItem("VS Computer"); final JCheckBoxMenuItem item3 = new JCheckBoxMenuItem("Play as X"); final JCheckBoxMenuItem item4 = new JCheckBoxMenuItem("Play as O"); final JCheckBoxMenuItem item5 = new JCheckBoxMenuItem("On"); final JCheckBoxMenuItem item6 = new JCheckBoxMenuItem("Off"); JMenuItem item7 = new JMenuItem("Restart"); JMenuItem item8 = new JMenuItem("Exit"); final JCheckBoxMenuItem item9 = new JCheckBoxMenuItem("Easy"); final JCheckBoxMenuItem item10 = new JCheckBoxMenuItem("Hard"); final JCheckBoxMenuItem item11 = new JCheckBoxMenuItem("Impossible"); final JCheckBoxMenuItem itemSword = new JCheckBoxMenuItem("Sword"); final JCheckBoxMenuItem itemSaber = new JCheckBoxMenuItem("Sabers"); final JCheckBoxMenuItem itemSkull = new JCheckBoxMenuItem("Skull"); final JCheckBoxMenuItem itemRing = new JCheckBoxMenuItem("One Ring"); final JCheckBoxMenuItem itemSmiley = new JCheckBoxMenuItem("Red Smiley"); final JCheckBoxMenuItem itemHydra = new JCheckBoxMenuItem("Hydra"); final JCheckBoxMenuItem itemDragon = new JCheckBoxMenuItem("Dragon"); final JCheckBoxMenuItem itemFinalFantasy = new JCheckBoxMenuItem("Final Fantasy 7"); final JCheckBoxMenuItem itemNight = new JCheckBoxMenuItem("Nighttime"); // Set the initial checkboxes to true (for play vs ai, as X, with graphics on) item2.setSelected(true); item3.setSelected(true); item5.setSelected(true); item11.setSelected(true); itemSaber.setSelected(true); itemRing.setSelected(true); itemDragon.setSelected(true); // Play against friend item.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { item.setSelected(true); item2.setSelected(false); multiPlayers = true; repaint(); } }); menu.add(item); // Checkbox for Selecting to play against AI item2.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { item2.setSelected(true); item.setSelected(false); if (currentPlayer == Symbol.X) ai = Symbol.O; else ai = Symbol.X; item3.setSelected(true); item4.setSelected(false); multiPlayers = false; } }); menu.add(item2); // Play as X item3.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // use temp variable to move after assigning symbols if (item4.getState() && !multiPlayers) temp = true; item3.setSelected(true); item4.setSelected(false); currentPlayer = Symbol.X; ai = Symbol.O; if (temp) aiMove(); repaint(); temp = false; } }); menu2.add(item3); // Play as O item4.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (item3.getState() && !multiPlayers) temp = true; item4.setSelected(true); item3.setSelected(false); currentPlayer = Symbol.O; ai = Symbol.X; if (temp) aiMove(); repaint(); temp = false; } }); menu2.add(item4); // Turn Graphics on item5.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { item5.setSelected(true); item6.setSelected(false); useImages = true; repaint(); } }); menu3.add(item5); // Turn Graphics off item6.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { item5.setSelected(false); item6.setSelected(true); useImages = false; repaint(); } }); menu3.add(item6); menu3.addSeparator(); menu3.add(xImageMenu); menu3.add(oImageMenu); menu3.add(backgroundMenu); // Choose Saber for X itemSaber.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemSword.setSelected(false); itemSaber.setSelected(true); itemSkull.setSelected(false); imageX = saber; repaint(); } }); xImageMenu.add(itemSaber); // Choose Sword for X itemSword.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemSword.setSelected(true); itemSaber.setSelected(false); itemSkull.setSelected(false); imageX = sword; repaint(); } }); xImageMenu.add(itemSword); // Choose Skull for X itemSkull.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemSword.setSelected(false); itemSaber.setSelected(false); itemSkull.setSelected(true); imageX = skull; repaint(); } }); xImageMenu.add(itemSkull); // Choose ring for O itemRing.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemRing.setSelected(true); itemSmiley.setSelected(false); itemHydra.setSelected(false); imageO = ring; repaint(); } }); oImageMenu.add(itemRing); // Choose red smiley for O itemSmiley.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemRing.setSelected(false); itemSmiley.setSelected(true); itemHydra.setSelected(false); imageO = smiley; repaint(); } }); oImageMenu.add(itemSmiley); // Choose hydra for O itemHydra.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemRing.setSelected(false); itemSmiley.setSelected(false); itemHydra.setSelected(true); imageO = hydra; repaint(); } }); oImageMenu.add(itemHydra); // Set dragon as background itemDragon.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemDragon.setSelected(true); itemFinalFantasy.setSelected(false); itemNight.setSelected(false); background = dragon; repaint(); } }); backgroundMenu.add(itemDragon); // Set final fantasy 7 as background itemFinalFantasy.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemDragon.setSelected(false); itemFinalFantasy.setSelected(true); itemNight.setSelected(false); background = finalfantasy; repaint(); } }); backgroundMenu.add(itemFinalFantasy); // Set night as background itemNight.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { itemDragon.setSelected(false); itemFinalFantasy.setSelected(false); itemNight.setSelected(true); background = night; repaint(); } }); backgroundMenu.add(itemNight); // Reset game item7.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { initialize(); } }); menu4.add(item7); // Exit game item8.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu4.add(item8); // Difficulty easy item9.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { difficulty = Difficulty.EASY; item9.setSelected(true); item10.setSelected(false); item11.setSelected(false); } }); menu5.add(item9); // Difficulty hard item10.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { difficulty = Difficulty.HARD; item10.setSelected(true); item9.setSelected(false); item11.setSelected(false); } }); menu5.add(item10); // Difficulty impossible item11.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { difficulty = Difficulty.IMPOSSIBLE; item11.setSelected(true); item9.setSelected(false); item10.setSelected(false); } }); menu5.add(item11); // Add Whole menu bar to frame frame.setJMenuBar(menuBar); // Create statusBar (updates will take place in paintComponent) statusBar = new JLabel(" "); statusBar.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15)); statusBar.setBorder(BorderFactory.createEmptyBorder(2, 5, 4, 5)); // Use container variable to set layout and pack everything nicely Container cp = frame.getContentPane(); cp.setLayout(new BorderLayout()); cp.add(this, BorderLayout.CENTER); cp.add(statusBar, BorderLayout.SOUTH); frame.pack(); board = new Symbol[ROWS][COLS]; initialize(); // Add the mouse listener. Use MouseAdapter rather than implement it this.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int currentCol = e.getX() / cellSize; int currentRow = e.getY() / cellSize; if (gameStatus == GameStatus.CONTINUE) { // If valid click, and spot is empty, make the move. Then check // to see if game is won. If not, and facing AI, ai moves. // Otherwise switch X and O if (currentRow >= 0 && currentRow < ROWS && currentCol >= 0 && currentCol < COLS && board[currentRow][currentCol] == Symbol.EMPTY) { board[currentRow][currentCol] = currentPlayer; checkState(currentPlayer); if (multiPlayers) currentPlayer = (currentPlayer == Symbol.X) ? Symbol.O : Symbol.X; if (gameStatus == GameStatus.CONTINUE && !multiPlayers) aiMove(); } } else { // Game is over, so re-initialize everything initialize(); } repaint(); } }); }