디렉토리를 읽는 응용 프로그램을 개발하고이 디렉토리의 각 맵에 button = 1 단계를 추가하려고했습니다. 2 단계에서 사용자가 모든 문서를 표시하는 버튼을 클릭합니다. 그지도에서. 이 (PDF 만) 문서도 단추로 표시됩니다. 사용자가 단추를 클릭하면 PDF가 뷰어에서 열립니다.JAVA GUI - 한 프레임에 두 개의 프레임이 있습니다.
두 클래스를 정의 했으므로 잘 작동합니다. 하지만 지금은 레이아웃에 문제가 있습니다. 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);
}
}
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) {}
}
}
당신은 생성자에서
Product
에
InfoPadUI
에서
this
인스턴스를 전달할 수 있습니다
하지만 두 개의 다른 부분이 있습니다. 하나는 infopadui 단계이고 다른 하나는 step2 제품 단추입니다. step1의 버튼을 클릭하지 않으면 2 단계에서 버튼이 표시되지 않습니다. 나는 jsplitpane에 대해 생각하고 있었습니까? – elo
예, splitPane 안에 또 다른 JPane을 추가하고이를 infopadUI에 전달하고 해당 JPane에 버튼을 추가하게하십시오. – rhbvkleef