R
r00kie2k6
Gast
Code:
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import com.sun.org.apache.bcel.internal.generic.IFNONNULL;
public class JTreeTest1 {
private JFrame frame;
private JSplitPane splitPane;
private JPanel contentPanel, rightPanel;
private JTree tree;
private JScrollPane scrollPane;
private InfoNode1 rootNode, stefanNode, dominikNode, normanNode, martinNode, andréNode, annikaNode, viktoriaNode, infoNodeStefan, infoNodeDominik, infoNodeNorman, InfoNodeMartin, InfoNodeAndré, InfoNodeAnnika, InfoNodeViktoria;
private JLabel lAlter, lBeruf, lBuero, lName, lVorname, lEmail, lTele, lSchule;
private JTextField tfAlter, tfBeruf, tfBuero, tfName, tfVorname, tfEmail, tfTele, tfSchule;
public JTreeTest1() {
init();
}
public void init() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
createFrame();
createSplitPane();
createPanel();
createTree();
createLabel();
createTextField();
addTreeListener();
createScollPane();
createLayout();
addLayout();
showFrame();
}
private void createFrame() {
frame = new JFrame("Auszubildene");
}
private void createSplitPane() {
splitPane = new JSplitPane();
}
private void createPanel() {
contentPanel = new JPanel();
rightPanel = new JPanel();
}
private void createTree() {
rootNode = new InfoNode1("Azubis");
InfoNodeViktoria = new InfoNode1("Info");
InfoNodeViktoria.setType(InfoNode1.WITH_INFO);
InfoNodeViktoria.setAlter("20");
InfoNodeViktoria.setBeruf("Bürokauffrau");
InfoNodeViktoria.setBuero("1");
InfoNodeViktoria.setEmail("fdf@we.de");
InfoNodeViktoria.setName("Nachname");
InfoNodeViktoria.setTele("(023");
InfoNodeViktoria.setVorname("Viktoria");
InfoNodeViktoria.setSchule("Schule");
viktoriaNode = new InfoNode1("Viktoria");
stefanNode.add(infoNodeStefan);
rootNode.add(stefanNode);
dominikNode.add(infoNodeDominik);
rootNode.add(dominikNode);
normanNode.add(infoNodeNorman);
rootNode.add(normanNode);
martinNode.add(InfoNodeMartin);
rootNode.add(martinNode);
andréNode.add(InfoNodeAndré);
rootNode.add(andréNode);
annikaNode.add(InfoNodeAnnika);
rootNode.add(annikaNode);
viktoriaNode.add(InfoNodeViktoria);
rootNode.add(viktoriaNode);
tree = new JTree(rootNode);
}
private void createLabel() {
lAlter = new JLabel("Alter:");
lBeruf = new JLabel("Beruf:");
lBuero = new JLabel("Büro:");
lName = new JLabel("Name:");
lVorname = new JLabel("Vorname:");
lEmail = new JLabel("Email:");
lTele = new JLabel("TelefonNr:");
lSchule = new JLabel("Schule:");
}
private void createTextField() {
tfAlter = new JTextField();
tfAlter.setEditable(false);
tfBeruf = new JTextField();
tfBeruf.setEditable(false);
tfBuero = new JTextField();
tfBuero.setEditable(false);
tfName = new JTextField();
tfName.setEditable(false);
tfVorname = new JTextField();
tfVorname.setEditable(false);
tfEmail = new JTextField();
tfEmail.setEditable(false);
tfTele = new JTextField();
tfTele.setEditable(false);
tfSchule = new JTextField();
tfSchule.setEditable(false);
}
private void addTreeListener() {
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent arg0) {
InfoNode1 node = (InfoNode1)tree.getLastSelectedPathComponent();
if(node.getType() == InfoNode1.WITH_INFO) {
tfName.setText(node.getName());
tfVorname.setText(node.getVorname());
tfAlter.setText(node.getAlter());
tfBeruf.setText(node.getBeruf());
tfEmail.setText(node.getEmail());
tfTele.setText(node.getTele());
tfBuero.setText(node.getBuero());
tfSchule.setText(node.getSchule());
} else {
tfName.setText("");
tfVorname.setText("");
tfAlter.setText("");
tfBeruf.setText("");
tfEmail.setText("");
tfTele.setText("");
tfBuero.setText("");
tfSchule.setText("");
}
System.out.println("Hatta geklickt in = " + node);
}
});
}
private void createScollPane() {
scrollPane = new JScrollPane(tree);
}
private void createLayout() {
frame.setLayout(new BorderLayout());
contentPanel.setLayout(new BorderLayout());
rightPanel.setLayout(null);
lName.setBounds(5,5,80,20);
tfName.setBounds(85,5,150,20);
lVorname.setBounds(5,30,80,20);
tfVorname.setBounds(85,30,150,20);
lAlter.setBounds(5,55,80,20);
tfAlter.setBounds(85,55,150,20);
lBeruf.setBounds(5,80,80,20);
tfBeruf.setBounds(85,80,150,20);
lEmail.setBounds(5,105,80,20);
tfEmail.setBounds(85,105,150,20);
lTele.setBounds(5,130,80,20);
tfTele.setBounds(85,130,150,20);
lBuero.setBounds(5,155,80,20);
tfBuero.setBounds(85,155,150,20);
lSchule.setBounds(5,180,80,20);
tfSchule.setBounds(85,180,150,20);
}
private void addLayout() {
rightPanel.add(lName);
rightPanel.add(tfName);
rightPanel.add(lVorname);
rightPanel.add(tfVorname);
rightPanel.add(lAlter);
rightPanel.add(tfAlter);
rightPanel.add(lBeruf);
rightPanel.add(tfBeruf);
rightPanel.add(lEmail);
rightPanel.add(tfEmail);
rightPanel.add(lTele);
rightPanel.add(tfTele);
rightPanel.add(lBuero);
rightPanel.add(tfBuero);
rightPanel.add(lSchule);
rightPanel.add(tfSchule);
splitPane.setLeftComponent(scrollPane);
splitPane.setRightComponent(rightPanel);
splitPane.setDividerLocation(200);
contentPanel.add(splitPane);
frame.setContentPane(contentPanel);
}
private void showFrame() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(600,400));
frame.setVisible(true);
}
}
So schaut mein Code jetzt aus, ich würde gerne im unteren Bereich, also unter den Textfeldern ein Bild der jeweiligen Person.
Könnte mir da jemand weiter helfen.
Den Code habe ich mit meinem Ausbilder zusammen gemacht.
Über Hilfe würde ich mich sehr freuen.