Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA GUI-一个框架中的两个框架_Java_Swing_Pdf_User Interface_Frame - Fatal编程技术网

JAVA GUI-一个框架中的两个框架

JAVA GUI-一个框架中的两个框架,java,swing,pdf,user-interface,frame,Java,Swing,Pdf,User Interface,Frame,我试图开发一个应用程序,它正在读取一个目录,并为此目录中的每个地图添加一个按钮=步骤1。在步骤2中,用户单击按钮以显示该地图中的所有文档。这些仅有的PDF文档也显示为按钮,如果用户点击按钮,PDF将在查看器中打开 我定义了两个类,以此类推,它工作得很好。但现在我有一个布局问题。步骤1中的按钮位于一个帧中,步骤2中的按钮位于另一个帧中。我希望有一个框架,以便在左侧是步骤1中的动态按钮,在右侧我希望有步骤2中的按钮,或者PDf也可以显示为tumblnail的按钮。如果我点击左边的按钮,右边就会被更新

我试图开发一个应用程序,它正在读取一个目录,并为此目录中的每个地图添加一个按钮=步骤1。在步骤2中,用户单击按钮以显示该地图中的所有文档。这些仅有的PDF文档也显示为按钮,如果用户点击按钮,PDF将在查看器中打开

我定义了两个类,以此类推,它工作得很好。但现在我有一个布局问题。步骤1中的按钮位于一个帧中,步骤2中的按钮位于另一个帧中。我希望有一个框架,以便在左侧是步骤1中的动态按钮,在右侧我希望有步骤2中的按钮,或者PDf也可以显示为tumblnail的按钮。如果我点击左边的按钮,右边就会被更新

有人能帮我吗

   package infopad;

   import java.awt.GridLayout;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;

   import javax.swing.JButton;
   import javax.swing.JFrame;

   import java.io.File;


   public class infopadUI extends JFrame implements ActionListener {

   public infopadUI() {
    File directory = null;

    //Öffne Hauptverzeichnis
    directory = new File("c:/Produktordner");

    int numberfiles = 0;

    // Inhalt von directory
    File[] files = directory.listFiles();

         //Number of Products in directory
    numberfiles = files.length;

    setSize(600, 600);
    setLocationRelativeTo(null);
    setLayout(new GridLayout(5, 6));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    for (int i = 1; i < numberfiles; i++) {
        //Name für Button aus Verzeichnisliste holen
        File file = files[i];

        JButton button = new JButton(file.getName());
        button.setActionCommand(file.getName());
        button.addActionListener(this);
        add(button);

           }
       }

       public static void main(String[] args) {


    new infopadUI().setVisible(true);



       }

       public void actionPerformed(ActionEvent e) {
    String  productnumber = e.getActionCommand();

    product p1 = new product(productnumber);       

       }



   }

您可以将此实例从InfoPadUI传递到构造函数中的产品:而不是新的InfoPadUI。。。。做新的InfoPaduitis。。。。在infopadUI中,将构造函数更改为接受JFrame,并使用该JFrame打开按钮。去掉infopadUI中的JFrame

,但我有两个不同的部分,一个是步骤1 infopadUI的按钮,另一个是步骤2产品的按钮。如果我不点击第1步的按钮,在第2部分中不会显示任何按钮。我在考虑jsplitpane?是的,然后在splitPane中添加另一个JPane并将其传递给infopadUI,然后让它将按钮添加到该JPane
   package infopad;

   import java.awt.Desktop;
   import java.awt.GridLayout;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;

   import javax.swing.JButton;
   import javax.swing.JFrame;

   import java.io.File;




   public class product extends JFrame implements ActionListener{

public product(String productnumber)
{       
    String map;
    String doc;


    map = ("c:/Produktordner/")+productnumber;


    File directory = null;

    //Öffne Hauptverzeichnis
    directory = new File(map);

    int numberfiles = 0;

    // Inhalt von directory
    File[] files = directory.listFiles();

  //Number of Products in directory
    numberfiles = files.length;

    setSize(600, 600);
    setLocationRelativeTo(null);
    setLayout(new GridLayout(5, 6));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    for (int i = 1; i < numberfiles; i++) {
        //Name für Button aus Verzeichnisliste holen
        File file = files[i];

        JButton button = new JButton(file.getName());
        doc = map+"/"+file.getName();



        button.setActionCommand(doc);
        button.addActionListener(this);
        add(button);

    }
    setVisible(true);

}

public static void main(String[] args) {




}

public void actionPerformed(ActionEvent ae) {
    String  doc = ae.getActionCommand();

   try {
              Desktop.getDesktop().open(new File(doc));
    } catch (Exception e) {}

       }
   }