Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NEWFAMILYTREE.JAVA:
- package familyTreeTest;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.EventQueue;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTabbedPane;
- import net.miginfocom.swing.MigLayout;
- import javax.swing.SwingConstants;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class NewFamilyTree {
- private JFrame frame;
- private JPanel panel_1;
- private JScrollPane scrollPane;
- private JTabbedPane tabbedPane;
- int cooX = 5;
- int cooY = 90;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- NewFamilyTree window = new NewFamilyTree();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public NewFamilyTree() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setTitle("New family tree");
- frame.getContentPane().setBackground(new Color(135, 206, 250));
- frame.setBounds(100, 100, 906, 569);
- frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- panel.setBackground(new Color(30, 144, 255));
- frame.getContentPane().add(panel, BorderLayout.EAST);
- panel.setLayout(new MigLayout("", "[]", "[][][][][][][][]"));
- JButton newPersonButton = new JButton("New Person");
- newPersonButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- final Data data = NewPerson.createPerson(frame);
- if (data != null) {
- String Val = data.CBvalue;
- if (Val == "mother") {
- JLabel lblHomer = new JLabel(data.names);
- lblHomer.setIcon(new ImageIcon(data.fileID));
- cooX = cooX + 20;
- cooY = cooY - 20;
- panel_1.add(lblHomer, "cell " + cooX + " " + cooY);
- panel_1.revalidate();
- } else {
- JLabel lblHomer = new JLabel(data.names);
- lblHomer.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- final Data data = NewPerson.createPerson(frame);
- if (data != null) {
- String Val = data.CBvalue;
- if (Val == "mother") {
- JLabel lblHomer = new JLabel(data.names);
- lblHomer.setIcon(new ImageIcon(data.fileID));
- cooX = cooX + 20;
- cooY = cooY - 20;
- panel_1.add(lblHomer, "cell " + cooX + " " + cooY);
- panel_1.revalidate();
- }}}
- });
- lblHomer.setIcon(new ImageIcon(data.fileID));
- panel_1.add(lblHomer, "cell " + cooX + " " + cooY);
- panel_1.revalidate();
- }
- }
- }
- });
- panel.add(newPersonButton, "cell 0 5");
- JButton btnNewButton_1 = new JButton("New button");
- panel.add(btnNewButton_1, "cell 0 6");
- tabbedPane = new JTabbedPane(JTabbedPane.TOP);
- frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
- scrollPane = new JScrollPane(null);
- tabbedPane.addTab("Tree", null, scrollPane, null);
- panel_1 = new JPanel(null);
- scrollPane.setViewportView(panel_1);
- panel_1.setLayout(new MigLayout(
- "",
- "[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]",
- "[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]"));
- JScrollPane scrollPane_1 = new JScrollPane();
- tabbedPane.addTab("Info", null, scrollPane_1, null);
- frame.repaint();
- }
- }
- NEWPERSON.JAVA:
- package familyTreeTest;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dialog;
- import java.awt.Frame;
- import java.awt.Window;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JDialog;
- import javax.swing.JFileChooser;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import javax.swing.SwingUtilities;
- import net.miginfocom.swing.MigLayout;
- public class NewPerson extends JPanel {
- private JTextField textFieldNames;
- private JButton selectPictureButton;
- private JLabel labelDateOfBirth;
- private JTextField textFieldDateOfBirth;
- private JLabel labelShortBio;
- private JTextArea textAreaBio;
- private JLabel labelSelectPicture;
- private JButton buttonAdd;
- private String fileID;
- private Data data;
- private JComboBox comboBox;
- /**
- * Create the application.
- */
- private NewPerson() {
- initialize();
- }
- public static Data createPerson(Component comp) {
- NewPerson newPerson = new NewPerson();
- Window win = SwingUtilities.getWindowAncestor(comp);
- JDialog dialog = null;
- if (win instanceof Frame) {
- dialog = new JDialog((Frame) win, "New person", true);
- } else if (win instanceof Dialog) {
- dialog = new JDialog((Dialog) win, "New person", true);
- } else {
- dialog = new JDialog((Frame) null, "New person", true);
- }
- newPerson.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Object source = e.getSource();
- if (source instanceof Component) {
- Window win = SwingUtilities
- .getWindowAncestor((Component) source);
- win.dispose();
- }
- }
- });
- dialog.getContentPane().add(newPerson);
- dialog.pack();
- dialog.setLocationRelativeTo(comp);
- dialog.setVisible(true);
- return newPerson.getData();
- }
- public void addActionListener(ActionListener listener) {
- listenerList.add(ActionListener.class, listener);
- }
- protected void fireActionPerformed() {
- ActionListener[] listeners = listenerList
- .getListeners(ActionListener.class);
- if (listeners != null && listeners.length > 0) {
- ActionEvent evt = new ActionEvent(this,
- ActionEvent.ACTION_PERFORMED, "created");
- for (ActionListener listener : listeners) {
- listener.actionPerformed(evt);
- }
- }
- }
- public Data getData() {
- return data;
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- setBackground(new Color(135, 206, 250));
- setLayout(new MigLayout("", "[][][grow]", "[][][][grow][][][]"));
- JLabel labelNames = new JLabel("Name and Surname:");
- add(labelNames, "cell 1 1,alignx trailing");
- textFieldNames = new JTextField();
- add(textFieldNames, "cell 2 1,growx");
- textFieldNames.setColumns(10);
- labelDateOfBirth = new JLabel("Date of birth:");
- add(labelDateOfBirth, "cell 1 2,alignx center,aligny center");
- textFieldDateOfBirth = new JTextField();
- add(textFieldDateOfBirth, "cell 2 2,growx");
- textFieldDateOfBirth.setColumns(10);
- labelShortBio = new JLabel("Bio:");
- add(labelShortBio, "cell 1 3,alignx center,aligny center");
- textAreaBio = new JTextArea();
- add(textAreaBio, "cell 2 3,grow");
- labelSelectPicture = new JLabel("Select picture:");
- add(labelSelectPicture, "cell 1 4,alignx center,aligny center");
- selectPictureButton = new JButton("...");
- selectPictureButton.setBackground(new Color(30, 144, 255));
- selectPictureButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- JFileChooser chooser = new JFileChooser(new File(System
- .getProperty("user.home") + "\\Desktop"));
- chooser.setDialogTitle("Select Location");
- chooser.setFileSelectionMode(JFileChooser.APPROVE_OPTION);
- chooser.setAcceptAllFileFilterUsed(false);
- if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
- fileID = chooser.getSelectedFile().getPath();
- // txtField.setText(fileID);
- }
- }
- });
- add(selectPictureButton, "cell 2 4");
- String[] persons = { "this is my first person", "mother", "father",
- "brother", "sister", "spouse", "son", "daughter" };
- comboBox = new JComboBox(persons);
- add(comboBox, "cell 2 5,growx");
- buttonAdd = new JButton("Add");
- buttonAdd.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String names = textFieldNames.getText();
- String dateBirth = textFieldDateOfBirth.getText();
- String bio = textAreaBio.getText();
- String CBvalue = comboBox.getSelectedItem().toString();
- Boolean.valueOf(CBvalue);
- System.out.print(CBvalue);
- data = new Data(names, dateBirth, bio, fileID, CBvalue);
- fireActionPerformed();
- }
- });
- buttonAdd.setBackground(new Color(30, 144, 255));
- add(buttonAdd, "cell 2 6,grow");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement