Guest User

Untitled

a guest
Apr 7th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. public class ClockFrame implements ActionListener {
  7. JFrame frame;
  8. JPanel p1;
  9. JLabel l1 = new JLabel();
  10. JLabel l2 = new JLabel();
  11. String [] s = {"Лос-Анджелес","Нью-Йорк","Москва","Лондон","Париж","Сидней","Токио",
  12. "Сантьяго","Каир","Текущее время"};
  13. JButton[]b = new JButton[s.length];
  14. runningTime p;
  15. LabelTown lb;
  16. public void StartFrame(){
  17. frame = new JFrame();
  18. p = new runningTime();
  19. p.getS();
  20. l1 = p.l1;
  21. lb = new LabelTown();
  22. l2 = lb.l1;
  23. l1.setHorizontalAlignment(JLabel.CENTER);
  24. p1 = new JPanel(new GridLayout(1,1));
  25. p1.add(l2);
  26. p1.add(l1);
  27. for(int i = 0;i<s.length;i++){
  28. b[i] =new JButton(s[i]);
  29. }
  30. for(int i = 0;i<b.length;i++){
  31. p1.add(b[i]);
  32. b[i].addActionListener(this);
  33. }
  34. frame.add(p1);
  35. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();//этой штукой получаем размер экрана, круто
  36. frame.setSize(d.width, 200);
  37. frame.setLocationRelativeTo(null);
  38. frame.setVisible(true);
  39. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40. }
  41.  
  42.  
  43. public void actionPerformed(ActionEvent e) {
  44. int [] r = {1,2,3,4,5,6,7,8,9,0};
  45. for(int i = 0;i<b.length;i++){
  46. if(e.getSource()==b[i]){
  47. p.setI(r[i]);
  48. lb.setS(s[i]);
  49. }
  50. }
  51.  
  52. }
  53.  
  54. public static void main(String[] args) {
  55. ClockFrame fr = new ClockFrame();
  56. fr.StartFrame();
  57. }
  58. }
Add Comment
Please, Sign In to add comment