JAVA GUI界面包

  1. import javax.swing.*;
  2. import java.awt.*;
  3. public class GuiJava extends JFrame {
  4.     
  5.     Container container;
  6.     //container size
  7.     public GuiJava (int width, int height, String name) {
  8.         super(name);
  9.         setBasic(width, height);
  10.     }
  11.     
  12.     public GuiJava (String name) {
  13.         super(name);
  14.         //default
  15.         setBasic(200200);
  16.     }
  17.     
  18.     public void setBasic(int width, int height)
  19.     {
  20.         container = this.getContentPane();
  21.         container.setLayout(null);
  22.         this.setResizable(false);
  23.         this.setVisible(true);
  24.         this.setSize(width, height);
  25.         this.setLocation(500300);
  26.         this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
  27.     }
  28.     
  29.     //component location
  30.     public void addComponentSet(Component compo0, int x, int y)
  31.     {
  32.         compo0.setLocation(x, y);
  33.         //default
  34.         compo0.setSize(5050);
  35.         container.add(compo0);
  36.     }
  37.     
  38.     //component location and size
  39.     public void addComponentSet(Component compo0, int x, int y, int width, int height)
  40.     {
  41.         compo0.setSize(width, height);
  42.         compo0.setLocation(x, y);
  43.         container.add(compo0);
  44.     }
  45.     
  46. }
以下給出一個實例
看看是如何使用
         
  1. import javax.swing.*;
  2. public class Sample {
  3.     public static void main (String[] args) {   
  4.         GuiJava com = new GuiJava("java");
  5.         JLabel label = new JLabel("hello");
  6.         com.addComponentSet(label, 1010);
  7.     }
  8. }    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章