Ich möchte die hinzuzufügenden Informationen in jpanel jscrollpane einfügen, wenn Sie auf jeden Baumknoten klicken.

Ich möchte die Informationen in jpanel jscrollpane einfügen, wenn Sie auf jeden Baumknoten klicken ... Bitte ... !!!

1.Ich möchte den Status des ausgewählten Baumknotens in Tree.java steuern, in dem Frame.java

Tree.java

package pms;
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

public class Tree extends JTree {
private JTree tree;
public static int selectItem = 0;

public JTree CreateTree() {
    setLayout(new BorderLayout());
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Management");
    DefaultMutableTreeNode bigLeaf1 = new DefaultMutableTreeNode("Generl Affair");
    DefaultMutableTreeNode bigLeaf2 = new DefaultMutableTreeNode("Personal Affair");
    final DefaultMutableTreeNode leaf2 = new DefaultMutableTreeNode("Recruit");
    final DefaultMutableTreeNode leaf3 = new DefaultMutableTreeNode("test");

    bigLeaf1.add(leaf2);
    bigLeaf2.add(leaf3);
    root.add(bigLeaf1);
    root.add(bigLeaf2);
    tree = new JTree(root);

    tree.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            TreePath tp = tree.getPathForLocation(e.getX(), e.getY());
            if (e.getClickCount() >= 2) {
                if (tp.getLastPathComponent() == leaf2) {
                    selectItem = 2;
                    System.out.println(selectItem);
                } else if (tp.getLastPathComponent() == leaf3) {
                    selectItem = 3;
                    System.out.println(selectItem);
                }
            }
        }
    });

    return tree;
    }

    public int selectedItem() {
        return selectItem;
    }
}

Frame.java

package pms;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class Frame extends JFrame implements Runnable {
    static int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    static int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    private JPanel pan1, pan2, pan3, pan4;
    public static JScrollPane jsp2;
    public Tree tree;
    public static ArrayList<Viewer> ViewArr = new ArrayList<Viewer>();
    public static int selectItem = 0;

    public Frame() {
        setTitle("Personal Management System");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().setLayout(null); // AbsoulteLayout

        /** Create MenuBar */
        menuBar menubar = new menuBar();
        setJMenuBar(menubar.CreateMenuBar());

        pan1 = new JPanel(new GridLayout()); // TreeNode ScrollPane
        pan2 = new JPanel(new BorderLayout()); // toolbar & ScrollPane2
        pan1.setBounds(0, 0, 350, 950); // Fixed Panel Size
        pan2.setBounds(350, 0, 1300, 950);
        getContentPane().add(pan1);
        getContentPane().add(pan2);

        /** Create Tree */
        tree = new Tree();

        JScrollPane jsp1 = new JScrollPane(tree.CreateTree(), v, h);
        pan1.add(jsp1);

        /** Create toolbar Panel */
        pan3 = new toolBar().CreateToolbar();
        pan2.setLayout(new BorderLayout());
        pan2.add(pan3, "North");

        /** Create viewer ScrollPane */
        jsp2 = new JScrollPane(v, h);
        jsp2.setBackground(Color.cyan);

        pan2.add(jsp2, "East");
        setSize(1300, 950);
        setVisible(true);
    }

    public void ShowInterViewer() {
        selectItem = tree.selectedItem();
        try {
            if (selectItem == 2) {
                System.out.println("222");
            } else if (selectItem == 3) {
                System.out.println("333");
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Frame frame = new Frame();
        frame.run();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
            }
        });
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
        ShowInterViewer();
    }
}

Viewer.java

    package pms;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Viewer extends JPanel implements ActionListener{
    private JPanel jp;
    private JTextField tf1, tf2, tf3, tf4, tf5, tf6;
    private JLabel lb1, lb2, lb3, lb4, lb5, lb6;
    private JButton btn1;
    private String name, sex, pass, phone, picturePath, filePath;
    private Date birthday, interviewDate;

    public Viewer(String name, Date birthday, String sex, Date interviewDate, String pass, String phone) {
        setName(name);
        setSex(sex);
        setPass(pass);
        setPass(pass);
        CreateViewer();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        if(sex.equals("M")){
            this.sex = "남자";
        }else if(sex.equals("W")){
            this.sex = "여자";
        }
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        if(pass.equals("Y")){
            this.pass = "합격";
        }else if(pass.equals("N")){
            this.pass = "불합격";
        }
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPicturePath() {
        return picturePath;
    }

    public void setPicturePath(String picturePath) {
        this.picturePath = picturePath;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Date getInterviewDate() {
        return interviewDate;
    }

    public void setInterviewDate(Date interviewDate) {
        this.interviewDate = interviewDate;
    }

    public JPanel CreateViewer(){
        jp = new JPanel(new BorderLayout());

        tf1 = new JTextField(getName());
        tf1.setColumns(20);
        //tf1.setBounds(50,50,10,10);
        tf2 = new JTextField();
        tf2.setColumns(20);
        tf3 = new JTextField();
        tf3.setColumns(20);
        tf4 = new JTextField();
        tf4.setColumns(20);
        tf5 = new JTextField();
        tf5.setColumns(20);
        tf6 = new JTextField();
        tf6.setColumns(20);

        lb1 = new JLabel("이름");
        lb2 = new JLabel("생년월일");
        lb3 = new JLabel("성별");
        lb4 = new JLabel("면접일자");
        lb5 = new JLabel("합격여부");
        lb6 = new JLabel("연락처");

        btn1 = new JButton("이력서 보기");



        jp.add(tf1);
        jp.add(tf2);
        jp.add(tf3);
        jp.add(tf4);
        jp.add(tf5);
        jp.add(tf6);
        jp.add(lb1);
        jp.add(lb2);
        jp.add(lb3);
        jp.add(lb4);
        jp.add(lb5);
        jp.add(lb6);
        jp.add(btn1);

        return jp;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

    }
}

Antworten auf die Frage(2)

Ihre Antwort auf die Frage