Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- public class MovingSignPanel extends JPanel implements ActionListener{
- JMenuBar b;
- JMenu menu = new JMenu("Hour of Day");
- JMenuItem morning = new JMenuItem("Morning");
- JMenuItem evening = new JMenuItem("Evening");
- private Timer timer = new Timer(20, this);
- int xPos = 230;
- int yPos = 350;
- final int X_DISPLACE = 150;
- JTextField phrase = new JTextField(5);
- JButton start = new JButton("Start");
- JButton stop = new JButton("Stop");
- JButton quit = new JButton("Quit");
- public MovingSignPanel(JMenuBar bar){
- setPreferredSize(new Dimension(800, 800));
- this.b = bar;
- b.add(menu);
- menu.add(morning);
- morning.addActionListener(this);
- menu.add(evening);
- evening.addActionListener(this);
- setBackground(Color.darkGray);
- this.add(phrase);
- this.add(start);
- start.addActionListener(this);
- this.add(stop);
- stop.addActionListener(this);
- this.add(quit);
- quit.addActionListener(this);
- }
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- g.setColor(Color.gray);
- g.fillRect(200,200,400, 500);
- g.setColor(Color.orange);
- g.fillRect(250,250,60,60);
- g.fillRect(375,250,60,60);
- g.fillRect(500,250,60,60);
- g.setColor(Color.white);
- g.fillRect(200,335,400,85);
- g.setColor(Color.orange);
- g.fillRect(250,445,60,60);
- g.fillRect(375,445,60,60);
- g.fillRect(500,445,60,60);
- g.fillRect(343,570,126,230);
- g.setColor(Color.lightGray);
- g.fillRect(0,700,800,700);
- for(int i = 0; i < 10; i++)
- g.drawString(phrase.getText(),(xPos + 50*i)%600,yPos);
- g.setColor(Color.darkGray);
- g.fillRect(600, 335, 200, 85);
- g.fillRect(0, 335, 200, 85);
- }
- public void actionPerformed(ActionEvent e){
- if(e.getSource() == quit){System.exit(0);}
- if(e.getSource() == timer){xPos += 2;}
- if(e.getSource() == morning){setBackground (Color.yellow);}
- if(e.getSource() == evening){setBackground(Color.darkGray);}
- if(e.getSource() == stop){timer.stop();}
- if(e.getSource() == start){timer.start();}
- repaint();
- }
- public static void main(String[] args){
- JMenuBar jbar = new JMenuBar();
- MovingSignPanel msp = new MovingSignPanel(jbar);
- JFrame frame = new JFrame();
- frame.setSize(800, 800);
- frame.add(msp);
- frame.setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement