Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. /**
  2. *
  3. */
  4. package gui;
  5.  
  6. import javax.swing.*;
  7.  
  8. import gui.GUI;
  9.  
  10. import java.awt.*;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.util.Locale;
  14. import java.util.ResourceBundle;
  15.  
  16. /**
  17. * @author Michelle
  18. *
  19. */
  20. public class GUI extends JFrame implements ActionListener {
  21. ResourceBundle res, res1, res2;
  22. JFrame frame;
  23. JButton button, button1, button2, button3, button4;
  24. JLabel label, label1,label2,label3, label4;
  25. JScrollPane output;
  26. JComboBox<String> combo;
  27. String[] array;
  28.  
  29. public GUI()
  30. {
  31. Locale loc = new Locale("fr"); //create Locale for French in France
  32.  
  33. res = res.getBundle("programResource.ProgramResource_fr",loc); //Create resource bundle
  34. res1 = res1.getBundle("programResource.ProgramResource_jp",loc);
  35. res2 = res2.getBundle("programResource.ProgramResource_en",loc);
  36.  
  37. Container c = getContentPane();
  38. JPanel p = new JPanel();
  39. String[] array = {"English", "French", "Japanese"};
  40. combo = new JComboBox<String>(array);
  41. output = new JScrollPane(combo);
  42. combo.addActionListener(this);
  43.  
  44. JMenuBar mb = new JMenuBar();
  45.  
  46. mb.add(output);
  47.  
  48. setJMenuBar(mb);
  49.  
  50. label = new JLabel();
  51. label1 = new JLabel();
  52. label2= new JLabel();
  53. label3 = new JLabel();
  54. label4 = new JLabel();
  55.  
  56. ImageIcon apple = new ImageIcon("apple.jpg");
  57. label.setIcon(apple);
  58. button = new JButton("Apple");
  59. button.addActionListener(this);
  60.  
  61. ImageIcon banana = new ImageIcon("banana.jpg");
  62. label1.setIcon(banana);
  63. button1 = new JButton("banana");
  64. button1.addActionListener(this);
  65.  
  66. ImageIcon grapes = new ImageIcon("grapes.jpg");
  67. label2.setIcon(grapes);
  68. button2 = new JButton("Grapes");
  69. button2.addActionListener(this);
  70.  
  71. ImageIcon orange = new ImageIcon("orange.jpg");
  72. label3.setIcon(orange);
  73. button3 = new JButton("Orange");
  74. button3.addActionListener(this);
  75.  
  76. ImageIcon pear = new ImageIcon("pear.jpg");
  77. label4.setIcon(pear);
  78. button4 = new JButton("Pear");
  79. button4.addActionListener(this);
  80.  
  81. p.add(label);
  82. p.add(label1);
  83. p.add(label2);
  84. p.add(label3);
  85. p.add(label4);
  86. p.add(button);
  87. p.add(button1);
  88. p.add(button2);
  89. p.add(button3);
  90. p.add(button4);
  91. c.add(p);
  92.  
  93. setSize(425,300);
  94. setVisible(true);
  95. }
  96.  
  97. //French
  98. public void actionPerformed(ActionEvent a) {
  99. Button(a);
  100. Button1(a);
  101. Button2(a);
  102. Button3(a);
  103. Button4(a);
  104.  
  105. }
  106.  
  107. public void Button(ActionEvent a) {
  108. if (a.getSource() instanceof JComboBox) {
  109. // TODO Auto-generated method stub
  110. JComboBox ref = (JComboBox)a.getSource();
  111.  
  112. if(ref.getSelectedItem().equals("French"))
  113. {
  114. button.setText(res.getString("computeButton"));
  115. }
  116. else if(ref.getSelectedItem().equals("Japanese"))
  117. {
  118. button.setText(res1.getString("computeButton1_jp"));
  119. }
  120. else if(ref.getSelectedItem().equals("English"))
  121. {
  122. button.setText(res2.getString("computeButton_en"));
  123. }
  124. }
  125. }
  126.  
  127. public void Button1(ActionEvent a) {
  128. if (a.getSource() instanceof JComboBox) {
  129. // TODO Auto-generated method stub
  130. JComboBox ref = (JComboBox)a.getSource();
  131.  
  132. if(ref.getSelectedItem().equals("French"))
  133. {
  134. button1.setText(res.getString("computeButton1"));
  135. }
  136. else if(ref.getSelectedItem().equals("Japanese"))
  137. {
  138. button1.setText(res1.getString("computeButton1_jp"));
  139. }
  140. else if(ref.getSelectedItem().equals("English"))
  141. {
  142. button1.setText(res2.getString("computeButton1_en"));
  143. }
  144. }
  145. }
  146.  
  147. public void Button2(ActionEvent a) {
  148. if (a.getSource() instanceof JComboBox) {
  149. // TODO Auto-generated method stub
  150. JComboBox ref = (JComboBox)a.getSource();
  151.  
  152. if(ref.getSelectedItem().equals("French"))
  153. {
  154. button2.setText(res.getString("computeButton2"));
  155. }
  156.  
  157. else if(ref.getSelectedItem().equals("Japanese"))
  158. {
  159. button2.setText(res1.getString("computeButton2_jp"));
  160. }
  161. else if(ref.getSelectedItem().equals("English"))
  162. {
  163. button2.setText(res2.getString("computeButton2_en"));
  164. }
  165. }
  166. }
  167.  
  168. public void Button3(ActionEvent a) {
  169. if (a.getSource() instanceof JComboBox) {
  170. // TODO Auto-generated method stub
  171. JComboBox ref = (JComboBox)a.getSource();
  172.  
  173. if(ref.getSelectedItem().equals("French"))
  174. {
  175. button3.setText(res.getString("computeButton3"));
  176. }
  177. else if(ref.getSelectedItem().equals("Japanese"))
  178. {
  179. button3.setText(res1.getString("computeButton3_jp"));
  180. }
  181. else if(ref.getSelectedItem().equals("English"))
  182. {
  183. button3.setText(res2.getString("computeButton3_en"));
  184. }
  185. }
  186. }
  187.  
  188. public void Button4(ActionEvent a) {
  189. if (a.getSource() instanceof JComboBox) {
  190. // TODO Auto-generated method stub
  191. JComboBox ref = (JComboBox)a.getSource();
  192.  
  193. if(ref.getSelectedItem().equals("French"))
  194. {
  195. button4.setText(res.getString("computeButton4"));
  196. }
  197.  
  198. else if(ref.getSelectedItem().equals("Japanese"))
  199. {
  200. button4.setText(res1.getString("computeButton4_jp"));
  201. }
  202. else if(ref.getSelectedItem().equals("English"))
  203. {
  204. button4.setText(res2.getString("computeButton4_en"));
  205. }
  206. }
  207. }
  208.  
  209. public static void main(String[] args) {
  210. // TODO Auto-generated method stub
  211. GUI gui = new GUI();
  212. gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  213. }
  214. }
  215.  
  216. Button button1 = new Button();
  217. button1.setCaption(ResourceBundle.getBundle("yourfile",your_locale).getLabel("fruit.banana"));
  218. button1.setIcon(CommonIcons.ADD);
  219. button1.addListener(new ClickListener()
  220. {
  221. private static final long serialVersionUID = 7855693595481663167L;
  222.  
  223. @Override
  224. public void buttonClick(ClickEvent event)
  225. {
  226. handleAddButton();
  227. }
  228. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement