Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Observable;
- import javax.swing.JFrame;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- import javax.swing.JRadioButtonMenuItem;
- public class ViewShop extends JFrame implements java.util.Observer {
- private ModelShop model;
- public ViewShop(ModelShop model)
- {
- super("View-Shop");
- this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
- this.setSize(500, 400);
- this.model = model;
- //register the observer
- model.addObserver(this);
- //create and add the components
- //Menübar und Menüs
- JMenuBar menubar = new JMenuBar();
- this.setJMenuBar(menubar);
- final JMenu menu = new JMenu();
- menu.setText("Online");
- menu.setBackground(Color.red);
- menubar.add(menu);
- //Menüitems
- final JRadioButtonMenuItem online = new JRadioButtonMenuItem("Work Online");
- final JRadioButtonMenuItem offline = new JRadioButtonMenuItem("Work Offline");
- offline.setSelected(true);
- menu.add(offline);
- menu.add(online);
- //ActionListener
- //offline
- offline.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- offline.setSelected(true);
- online.setSelected(false);
- menu.setBackground(Color.red);
- }
- });
- //online
- online.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- offline.setSelected(false);
- online.setSelected(true);
- menu.setBackground(Color.green);
- }
- });
- //pack and set visible
- //this.pack();
- this.setVisible(true);
- }
- @Override
- public void update(Observable arg0, Object arg1) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement