Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class ClockFrame implements ActionListener {
- JFrame frame;
- JPanel p1;
- JLabel l1 = new JLabel();
- JLabel l2 = new JLabel();
- String [] s = {"Лос-Анджелес","Нью-Йорк","Москва","Лондон","Париж","Сидней","Токио",
- "Сантьяго","Каир","Текущее время"};
- JButton[]b = new JButton[s.length];
- runningTime p;
- LabelTown lb;
- public void StartFrame(){
- frame = new JFrame();
- p = new runningTime();
- p.getS();
- l1 = p.l1;
- lb = new LabelTown();
- l2 = lb.l1;
- l1.setHorizontalAlignment(JLabel.CENTER);
- p1 = new JPanel(new GridLayout(1,1));
- p1.add(l2);
- p1.add(l1);
- for(int i = 0;i<s.length;i++){
- b[i] =new JButton(s[i]);
- }
- for(int i = 0;i<b.length;i++){
- p1.add(b[i]);
- b[i].addActionListener(this);
- }
- frame.add(p1);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();//этой штукой получаем размер экрана, круто
- frame.setSize(d.width, 200);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public void actionPerformed(ActionEvent e) {
- int [] r = {1,2,3,4,5,6,7,8,9,0};
- for(int i = 0;i<b.length;i++){
- if(e.getSource()==b[i]){
- p.setI(r[i]);
- lb.setS(s[i]);
- }
- }
- }
- public static void main(String[] args) {
- ClockFrame fr = new ClockFrame();
- fr.StartFrame();
- }
- }
Add Comment
Please, Sign In to add comment