Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- package gui;
- import javax.swing.*;
- import gui.GUI;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Locale;
- import java.util.ResourceBundle;
- /**
- * @author Michelle
- *
- */
- public class GUI extends JFrame implements ActionListener {
- ResourceBundle res, res1, res2;
- JFrame frame;
- JButton button, button1, button2, button3, button4;
- JLabel label, label1,label2,label3, label4;
- JScrollPane output;
- JComboBox<String> combo;
- String[] array;
- public GUI()
- {
- Locale loc = new Locale("fr"); //create Locale for French in France
- res = res.getBundle("programResource.ProgramResource_fr",loc); //Create resource bundle
- res1 = res1.getBundle("programResource.ProgramResource_jp",loc);
- res2 = res2.getBundle("programResource.ProgramResource_en",loc);
- Container c = getContentPane();
- JPanel p = new JPanel();
- String[] array = {"English", "French", "Japanese"};
- combo = new JComboBox<String>(array);
- output = new JScrollPane(combo);
- combo.addActionListener(this);
- JMenuBar mb = new JMenuBar();
- mb.add(output);
- setJMenuBar(mb);
- label = new JLabel();
- label1 = new JLabel();
- label2= new JLabel();
- label3 = new JLabel();
- label4 = new JLabel();
- ImageIcon apple = new ImageIcon("apple.jpg");
- label.setIcon(apple);
- button = new JButton("Apple");
- button.addActionListener(this);
- ImageIcon banana = new ImageIcon("banana.jpg");
- label1.setIcon(banana);
- button1 = new JButton("banana");
- button1.addActionListener(this);
- ImageIcon grapes = new ImageIcon("grapes.jpg");
- label2.setIcon(grapes);
- button2 = new JButton("Grapes");
- button2.addActionListener(this);
- ImageIcon orange = new ImageIcon("orange.jpg");
- label3.setIcon(orange);
- button3 = new JButton("Orange");
- button3.addActionListener(this);
- ImageIcon pear = new ImageIcon("pear.jpg");
- label4.setIcon(pear);
- button4 = new JButton("Pear");
- button4.addActionListener(this);
- p.add(label);
- p.add(label1);
- p.add(label2);
- p.add(label3);
- p.add(label4);
- p.add(button);
- p.add(button1);
- p.add(button2);
- p.add(button3);
- p.add(button4);
- c.add(p);
- setSize(425,300);
- setVisible(true);
- }
- //French
- public void actionPerformed(ActionEvent a) {
- Button(a);
- Button1(a);
- Button2(a);
- Button3(a);
- Button4(a);
- }
- public void Button(ActionEvent a) {
- if (a.getSource() instanceof JComboBox) {
- // TODO Auto-generated method stub
- JComboBox ref = (JComboBox)a.getSource();
- if(ref.getSelectedItem().equals("French"))
- {
- button.setText(res.getString("computeButton"));
- }
- else if(ref.getSelectedItem().equals("Japanese"))
- {
- button.setText(res1.getString("computeButton1_jp"));
- }
- else if(ref.getSelectedItem().equals("English"))
- {
- button.setText(res2.getString("computeButton_en"));
- }
- }
- }
- public void Button1(ActionEvent a) {
- if (a.getSource() instanceof JComboBox) {
- // TODO Auto-generated method stub
- JComboBox ref = (JComboBox)a.getSource();
- if(ref.getSelectedItem().equals("French"))
- {
- button1.setText(res.getString("computeButton1"));
- }
- else if(ref.getSelectedItem().equals("Japanese"))
- {
- button1.setText(res1.getString("computeButton1_jp"));
- }
- else if(ref.getSelectedItem().equals("English"))
- {
- button1.setText(res2.getString("computeButton1_en"));
- }
- }
- }
- public void Button2(ActionEvent a) {
- if (a.getSource() instanceof JComboBox) {
- // TODO Auto-generated method stub
- JComboBox ref = (JComboBox)a.getSource();
- if(ref.getSelectedItem().equals("French"))
- {
- button2.setText(res.getString("computeButton2"));
- }
- else if(ref.getSelectedItem().equals("Japanese"))
- {
- button2.setText(res1.getString("computeButton2_jp"));
- }
- else if(ref.getSelectedItem().equals("English"))
- {
- button2.setText(res2.getString("computeButton2_en"));
- }
- }
- }
- public void Button3(ActionEvent a) {
- if (a.getSource() instanceof JComboBox) {
- // TODO Auto-generated method stub
- JComboBox ref = (JComboBox)a.getSource();
- if(ref.getSelectedItem().equals("French"))
- {
- button3.setText(res.getString("computeButton3"));
- }
- else if(ref.getSelectedItem().equals("Japanese"))
- {
- button3.setText(res1.getString("computeButton3_jp"));
- }
- else if(ref.getSelectedItem().equals("English"))
- {
- button3.setText(res2.getString("computeButton3_en"));
- }
- }
- }
- public void Button4(ActionEvent a) {
- if (a.getSource() instanceof JComboBox) {
- // TODO Auto-generated method stub
- JComboBox ref = (JComboBox)a.getSource();
- if(ref.getSelectedItem().equals("French"))
- {
- button4.setText(res.getString("computeButton4"));
- }
- else if(ref.getSelectedItem().equals("Japanese"))
- {
- button4.setText(res1.getString("computeButton4_jp"));
- }
- else if(ref.getSelectedItem().equals("English"))
- {
- button4.setText(res2.getString("computeButton4_en"));
- }
- }
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- GUI gui = new GUI();
- gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
- Button button1 = new Button();
- button1.setCaption(ResourceBundle.getBundle("yourfile",your_locale).getLabel("fruit.banana"));
- button1.setIcon(CommonIcons.ADD);
- button1.addListener(new ClickListener()
- {
- private static final long serialVersionUID = 7855693595481663167L;
- @Override
- public void buttonClick(ClickEvent event)
- {
- handleAddButton();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement