Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4.  
  5. public class MovingSignPanel extends JPanel implements ActionListener{
  6. JMenuBar b;
  7. JMenu menu = new JMenu("Hour of Day");
  8. JMenuItem morning = new JMenuItem("Morning");
  9. JMenuItem evening = new JMenuItem("Evening");
  10. private Timer timer = new Timer(20, this);
  11. int xPos = 230;
  12. int yPos = 350;
  13. final int X_DISPLACE = 150;
  14. JTextField phrase = new JTextField(5);
  15. JButton start = new JButton("Start");
  16. JButton stop = new JButton("Stop");
  17. JButton quit = new JButton("Quit");
  18.  
  19.  
  20. public MovingSignPanel(JMenuBar bar){
  21. setPreferredSize(new Dimension(800, 800));
  22. this.b = bar;
  23. b.add(menu);
  24. menu.add(morning);
  25. morning.addActionListener(this);
  26. menu.add(evening);
  27. evening.addActionListener(this);
  28. setBackground(Color.darkGray);
  29. this.add(phrase);
  30. this.add(start);
  31. start.addActionListener(this);
  32. this.add(stop);
  33. stop.addActionListener(this);
  34. this.add(quit);
  35. quit.addActionListener(this);
  36. }
  37.  
  38. public void paintComponent(Graphics g){
  39. super.paintComponent(g);
  40. g.setColor(Color.gray);
  41. g.fillRect(200,200,400, 500);
  42. g.setColor(Color.orange);
  43. g.fillRect(250,250,60,60);
  44. g.fillRect(375,250,60,60);
  45. g.fillRect(500,250,60,60);
  46. g.setColor(Color.white);
  47. g.fillRect(200,335,400,85);
  48. g.setColor(Color.orange);
  49. g.fillRect(250,445,60,60);
  50. g.fillRect(375,445,60,60);
  51. g.fillRect(500,445,60,60);
  52. g.fillRect(343,570,126,230);
  53. g.setColor(Color.lightGray);
  54. g.fillRect(0,700,800,700);
  55. for(int i = 0; i < 10; i++)
  56. g.drawString(phrase.getText(),(xPos + 50*i)%600,yPos);
  57. g.setColor(Color.darkGray);
  58. g.fillRect(600, 335, 200, 85);
  59. g.fillRect(0, 335, 200, 85);
  60. }
  61.  
  62. public void actionPerformed(ActionEvent e){
  63. if(e.getSource() == quit){System.exit(0);}
  64. if(e.getSource() == timer){xPos += 2;}
  65. if(e.getSource() == morning){setBackground (Color.yellow);}
  66. if(e.getSource() == evening){setBackground(Color.darkGray);}
  67. if(e.getSource() == stop){timer.stop();}
  68. if(e.getSource() == start){timer.start();}
  69. repaint();
  70. }
  71.  
  72. public static void main(String[] args){
  73. JMenuBar jbar = new JMenuBar();
  74. MovingSignPanel msp = new MovingSignPanel(jbar);
  75. JFrame frame = new JFrame();
  76. frame.setSize(800, 800);
  77. frame.add(msp);
  78. frame.setVisible(true);
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement