1 16 package sample.amazon.amazonSimpleQueueService; 17 18 import sample.amazon.amazonSimpleQueueService.util.QueueManager; 19 20 import javax.swing.*; 21 import java.awt.*; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.awt.event.KeyEvent ; 25 import java.io.File ; 26 import java.io.IOException ; 27 28 33 public class AmazonSimpleQueueServiceOut extends JFrame { 34 private static final String HELP_FILE_NAME = "/docs/AmazonSimpleWebService.html"; 35 JTextField createQueue; 36 JTextField queueCode; 37 JTextField read; 38 JTextArea resuts; 39 JButton loadButton; 40 JButton deleteButton; 41 42 public AmazonSimpleQueueServiceOut() { 43 this.setBounds(200, 200, 450, 500); 44 this.setTitle("Amazon Simple Queue WS - Out"); 45 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 46 this.guiInit(); 47 } 48 49 private void guiInit() { 50 getContentPane().setLayout(new GridBagLayout()); 51 GridBagConstraints cons = new GridBagConstraints(); 52 cons.fill = GridBagConstraints.BOTH; 53 cons.insets = new Insets(5, 5, 5, 5); 54 cons.weightx = 100; 55 JLabel label0 = new JLabel("Enter Queue Name"); 56 this.add(label0, cons, 0, 0, 1, 1); 57 JLabel lable1 = new JLabel("Queue Code"); 58 this.add(lable1, cons, 1, 0, 1, 1); 59 createQueue = new JTextField(); 60 createQueue.setEditable(false); 61 this.add(createQueue, cons, 0, 1, 1, 1); 62 queueCode = new JTextField(); 63 queueCode.setEditable(false); 64 this.add(queueCode, cons, 1, 1, 1, 1); 65 JLabel lable2 = new JLabel("Read"); 66 this.add(lable2, cons, 0, 2, 1, 1); 67 read = new JTextField(); 68 read.setEditable(false); 69 this.add(read, cons, 0, 3, 2, 1); 70 JLabel label3 = new JLabel("Results"); 71 this.add(label3, cons, 0, 4, 1, 1); 72 resuts = new JTextArea(); 73 resuts.setEditable(false); 74 JScrollPane resultPane = new JScrollPane(resuts); 75 cons.weighty = 100; 76 this.add(resultPane, cons, 0, 5, 2, 1); 77 JPanel buttonPannel = new JPanel(); 78 loadButton = new JButton("Load Queue"); 79 loadButton.setActionCommand("1"); 80 deleteButton = new JButton("Delete Queue"); 81 deleteButton.setActionCommand("2"); 82 buttonPannel.add(loadButton); 83 buttonPannel.add(deleteButton); 84 cons.weightx = 0; 85 cons.weighty = 0; 86 this.add(buttonPannel, cons, 0, 6, 2, 1); 87 this.createQueue.addKeyListener(new ListenersOut(this.createQueue, this.queueCode, 88 this.read, this.resuts, this.loadButton, this.deleteButton)); 89 this.loadButton.addActionListener(new ListenersOut(this.createQueue, this.queueCode, 90 this.read, this.resuts, this.loadButton, this.deleteButton)); 91 this.resuts.addMouseMotionListener(new ListenersOut(this.createQueue, this.queueCode, 92 this.read, this.resuts, this.loadButton, this.deleteButton)); 93 this.deleteButton.addActionListener(new ListenersOut(this.createQueue, this.queueCode, 94 this.read, this.resuts, this.loadButton, this.deleteButton)); 95 96 AddMenuItems(); 97 } 98 99 private void add(Component c, GridBagConstraints cons, int x, int y, int w, int h) { 100 cons.gridx = x; 101 cons.gridy = y; 102 cons.gridheight = h; 103 cons.gridwidth = w; 104 this.getContentPane().add(c, cons); 105 } 106 107 private void AddMenuItems() { 108 JMenuBar menuBar = new JMenuBar(); 110 JMenu settingsMenu = new JMenu("Settings"); 111 settingsMenu.setMnemonic(KeyEvent.VK_S); 112 JMenuItem amazonKeyMenu = new JMenuItem("Set Amazon Key",KeyEvent.VK_G); 113 amazonKeyMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK)); 114 amazonKeyMenu.addActionListener(new ActionListener (){ 115 public void actionPerformed(ActionEvent e) { 116 setKey(); 117 } 118 }); 119 settingsMenu.add(amazonKeyMenu); 120 121 JMenu helpMenu = new JMenu("Help"); 122 JMenuItem mnuItemHelp = new JMenuItem("Show Help"); 123 helpMenu.add(mnuItemHelp); 124 125 mnuItemHelp.addActionListener(new ActionListener () { 126 public void actionPerformed(ActionEvent e) { 127 showHelp(); 128 } 129 }); 130 131 menuBar.add(settingsMenu); 132 menuBar.add(helpMenu); 133 setJMenuBar(menuBar); 134 } 135 136 private void setKey(){ 137 String key = JOptionPane.showInputDialog(this,"Set the Amazon Key",QueueManager.getKey()); 138 if (key!=null && !key.trim().equals("")){ 139 QueueManager.setKey(key); 140 } 141 } 142 143 146 private void showHelp() { 147 148 JFrame frame= new JFrame(); 149 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 150 frame.setLocation(screenSize.width/5, 151 screenSize.height/5); 152 frame.setSize(screenSize.width/2,screenSize.height/2); 153 154 BorderLayout layout = new BorderLayout(); 155 156 JScrollPane jsp ; 157 JEditorPane jep; 158 159 jep = new JEditorPane(); 160 jep.setEditable(false); 162 jep.setContentType("text/html"); 163 164 jsp = new JScrollPane(jep); 165 166 Container contentPane = frame.getContentPane(); 167 contentPane.setLayout(layout); 168 contentPane.add(jsp, BorderLayout.CENTER); 169 String helpDoc = System.getProperty("user.dir")+HELP_FILE_NAME; 170 171 try { 172 jep.setPage(new File (helpDoc).toURL()); 173 } catch (IOException e) { 174 JOptionPane.showMessageDialog(this,"Help file not detected","Help file error",JOptionPane.ERROR_MESSAGE); 175 return; 176 } 177 frame.setVisible(true); 178 } 179 180 } 181 | Popular Tags |