Guest User

Untitled

a guest
May 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package window.fullscrean;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Dimension;
  5. import java.awt.Toolkit;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11.  
  12. @SuppressWarnings("serial")
  13. public class LooksLikeFullScreen extends JFrame implements ActionListener {
  14.     String button_location[] = { BorderLayout.CENTER, BorderLayout.NORTH,
  15.             BorderLayout.WEST, BorderLayout.SOUTH, BorderLayout.EAST };
  16.     int button_num = button_location.length;
  17.  
  18.     JButton bu[] = new JButton[button_num];
  19.  
  20.     LooksLikeFullScreen() {
  21.         super("ActionListenerTest");
  22.  
  23.         for (int i = 0; i < button_num; i++) {
  24.             bu[i] = new JButton("BUTTON" + i);
  25.             bu[i].addActionListener(this);
  26.             add(bu[i], button_location[i]);
  27.         }
  28.         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  29.         System.out.println(d.getHeight() + "and" + d.getWidth());
  30.         setLocation(0, 0);
  31.         setSize((int) d.getWidth(), (int) d.getHeight());
  32.     }
  33.  
  34.     public void actionPerformed(ActionEvent e) {
  35.         Object so = e.getSource();
  36.         for (int i = 0; i < button_num; i++) {
  37.             if (so == bu[i]) {
  38.                 System.out.println("PushButton: " + bu[i].getText());
  39.             }
  40.         }
  41.     }
  42.  
  43.     public static void main(String[] args) {
  44.         LooksLikeFullScreen kb = new LooksLikeFullScreen();
  45.  
  46.         // 閉じるボタンの有効化
  47.         kb.setUndecorated(true);
  48.         kb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49.         kb.setVisible(true);
  50.  
  51.     }
  52. }
Add Comment
Please, Sign In to add comment