Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.util.Observable;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JMenu;
  9. import javax.swing.JMenuBar;
  10. import javax.swing.JMenuItem;
  11. import javax.swing.JRadioButtonMenuItem;
  12.  
  13.  
  14. public class ViewShop extends JFrame implements java.util.Observer {
  15.  
  16.     private ModelShop model;
  17.    
  18.     public ViewShop(ModelShop model)
  19.     {
  20.         super("View-Shop");
  21.         this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
  22.         this.setSize(500, 400);
  23.         this.model = model;
  24.        
  25.         //register the observer
  26.         model.addObserver(this);
  27.        
  28.        
  29.         //create and add the components
  30.        
  31.             //Menübar und Menüs
  32.             JMenuBar menubar = new JMenuBar();
  33.             this.setJMenuBar(menubar);
  34.             final JMenu menu = new JMenu();
  35.             menu.setText("Online");
  36.             menu.setBackground(Color.red);
  37.             menubar.add(menu);
  38.            
  39.             //Menüitems
  40.             final JRadioButtonMenuItem online = new JRadioButtonMenuItem("Work Online");
  41.             final JRadioButtonMenuItem offline = new JRadioButtonMenuItem("Work Offline");
  42.             offline.setSelected(true);
  43.            
  44.             menu.add(offline);
  45.             menu.add(online);
  46.        
  47.            
  48.            
  49.            
  50.            
  51.        
  52.         //ActionListener
  53.             //offline
  54.             offline.addActionListener(new ActionListener() {
  55.                 @Override
  56.                 public void actionPerformed(ActionEvent e) {
  57.                    
  58.                     offline.setSelected(true);
  59.                     online.setSelected(false);
  60.                     menu.setBackground(Color.red);
  61.                 }
  62.             });
  63.            
  64.             //online
  65.             online.addActionListener(new ActionListener() {
  66.                
  67.                 @Override
  68.                 public void actionPerformed(ActionEvent e) {
  69.                    
  70.                     offline.setSelected(false);
  71.                     online.setSelected(true);
  72.                     menu.setBackground(Color.green);
  73.                 }
  74.             });
  75.        
  76.        
  77.        
  78.         //pack and set visible
  79.         //this.pack();
  80.         this.setVisible(true);
  81.     }
  82.  
  83.      
  84.     @Override
  85.     public void update(Observable arg0, Object arg1) {
  86.         // TODO Auto-generated method stub
  87.        
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement