1 package animals.excercise2; 2 import java.awt ... - Infty Project

4 downloads 28 Views 41KB Size Report
ActionListener;. 5 import javax.swing.ComboBoxModel;. 6 import javax.swing. DefaultComboBoxModel;. 7 import javax.swing.JComboBox;. 8 import javax. swing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

package animals.excercise2; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JTextField; import javax.swing.WindowConstants; import javax.swing.SwingUtilities; import animals.MyException; /** * This code was edited or generated using CloudGarden's Jigloo * SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, * company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. * Use of Jigloo implies acceptance of these licensing terms. * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE. */ public class AnimalsFrame extends javax.swing.JFrame { private JPanel northPanel; private JComboBox jComboBox; private JLabel jLabel2; private JTextField widthField; private JLabel jLabel3; private JTextField heightField; private JSeparator jSeparator1; private JLabel jLabel1; private MainPanel mainPanel1; { //Set Look & Feel try { javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch(Exception e) { e.printStackTrace(); } } /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { AnimalsFrame inst = new AnimalsFrame(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } public AnimalsFrame() { super(); initGUI(); } private void initGUI() { try { BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { northPanel = new JPanel(); getContentPane().add(northPanel, BorderLayout.NORTH); northPanel.setPreferredSize(new java.awt.Dimension(592, 40));

81 { 82 jLabel1 = new JLabel(); 83 northPanel.add(jLabel1); 84 jLabel1.setText("\u30af\u30ea\u30c3\u30af\u3067\u52d5\u7269\u304c\u5897\u3048\u305f 85 \u308a\u9cf4\u3044\u305f\u308a\u3002\u3000\u3000\u3000\u52d5\u7269\u306e\u7a2e\u985e\uff1a"); 86 } 87 { 88 ComboBoxModel jComboBoxModel = 89 new DefaultComboBoxModel( 90 new String[] { " 猫 ", " 犬 ", " 鳥 " }); 91 jComboBox = new JComboBox(); 92 northPanel.add(jComboBox); 93 jComboBox.setModel(jComboBoxModel); 94 jComboBox.addActionListener(new ActionListener() { 95 public void actionPerformed(ActionEvent evt) { 96 System.out.println("jComboBox.actionPerformed, event="+evt); 97 mainPanel1.setAnimalType((((JComboBox)evt.getSource()).getSelectedIndex())) 98 ; 99 //TODO add your code for jComboBox.actionPerformed 100 } 101 }); 102 } 103 { 104 jLabel2 = new JLabel(); 105 northPanel.add(jLabel2); 106 jLabel2.setText(" \u753b\u50cf\u5e45"); 107 } 108 { 109 widthField = new JTextField(); 110 northPanel.add(widthField); 111 widthField.setText("100"); 112 } 113 { 114 jLabel3 = new JLabel(); 115 northPanel.add(jLabel3); 116 jLabel3.setText("\u3000\u3000\u753b\u50cf\u9ad8\u3055"); 117 } 118 { 119 heightField = new JTextField(); 120 northPanel.add(heightField); 121 heightField.setText("100"); 122 } 123 { 124 jSeparator1 = new JSeparator(); 125 northPanel.add(jSeparator1); 126 jSeparator1.setPreferredSize(new java.awt.Dimension(600, 2)); 127 } 128 } 129 { 130 mainPanel1 = new MainPanel(); 131 try{ 132 mainPanel1.init(); 133 } catch (MyException e){ 134 JOptionPane.showMessageDialog(this,e.getMessage(), "エラー", 135 JOptionPane.ERROR_MESSAGE); 136 System.exit(-1); 137 } 138 getContentPane().add(mainPanel1, BorderLayout.CENTER); 139 } 140 pack(); 141 setSize(600, 500); 142 } catch (Exception e) { 143 e.printStackTrace(); 144 } 145 } 146 147 public int getImgWidth(){ 148 int width=0; 149 try{ 150 width=Integer.parseInt(widthField.getText()); 151 }catch(NumberFormatException e){ 152 JOptionPane.showMessageDialog(this,"画像幅を整数で記入して下さい"); 153 } 154 return width; 155 } 156 public int getImgHeight(){ 157 int height=0; 158 try{ 159 height=Integer.parseInt(heightField.getText()); 160 }catch(NumberFormatException e){

161 162 163 164 165 166 }

JOptionPane.showMessageDialog(this,"画像幅を整数で記入して下さい"); } return height; }