java Imports如何工作(swing)?

时间:2015-06-30 17:01:02

标签: java swing user-interface import package

所以我尝试创建一个空边框,并且需要导入javax.swing.border.EmptyBorder;

但是我已经导入了javax.swing。*;

为什么我需要导入先前的导入?不是。*从swing包中导入所有内容。

我的源代码如下:

   import javax.swing.*;
   import javax.swing.border.EmptyBorder;

   import java.awt.*;
  /*
public class Gui extends JFrame {

//row1
JPanel row1 = new JPanel();
JButton reset = new JButton("Reset");
JButton play = new JButton("Play");

//row2
JPanel row2 = new JPanel();
JLabel option = new JLabel("Guess: ", JLabel.RIGHT);
JTextField text1 = new JTextField("0");
JTextField text2 = new JTextField("0");
JTextField text3 = new JTextField("0");

//row3
JPanel row3 = new JPanel();
JLabel answerL = new JLabel("Answer: ", JLabel.RIGHT);
JTextField answerB = new JTextField("", 0);
*/
public Gui(){
/*  super("Guess My Number");
    setSize(500, 800);
    GridLayout masterLayout = new GridLayout(4, 1);
    setLayout(masterLayout);


    FlowLayout layout1 = new FlowLayout(FlowLayout.LEFT);
    row1.setLayout(layout1);
    row1.add(reset);
    row1.add(play);
    add(row1);


    GridLayout layout2 = new GridLayout(1, 4, 30, 30);
    row2.setLayout(layout2);*/
    row2.setBorder(new EmptyBorder(0,100,0,200));
    /*row2.add(option);
    row2.add(text1);
    row2.add(text2);
    row2.add(text3);
    add(row2);

    GridLayout layout3 = new GridLayout(1,1, 10, 10);
    row3.setLayout(layout3);
    row3.add(answerL);
    row3.add(answerB);
    add(row3);


    setVisible(true);
}

public static void main(String[] args){
    Gui game = new Gui();
}
}
 */

1 个答案:

答案 0 :(得分:6)

Java中的嵌套包之间没有任何关系。

javax.swing.*只会导入直接在javax.swing中找到的类,从语言角度来看,javax.swing.border被视为完全不同的不相关包。