Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.Color.*;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.JButton;
- import javax.swing.JScrollPane;
- import javax.swing.JTextField;
- import javax.swing.JTable;
- import javax.swing.table.DefaultTableModel;
- public class UI extends JFrame implements ActionListener, ItemListener
- {
- final int SIZE = 400;
- JFrame frame = new JFrame();
- Container con = getContentPane();
- JPanel mainpnl1 = new JPanel();
- JPanel mainpnl2 = new JPanel();
- JPanel pnl1 = new JPanel();
- JPanel pnl2 = new JPanel();
- Font myFont1 = new Font("Times New Roman", Font.BOLD, 25);
- Font myFont2 = new Font("Times New Roman", Font.BOLD,20);
- Font myFont3 = new Font("Times New Roman", Font.BOLD,14);
- Font buttonFont1 = new Font("Arial", Font.BOLD, 24);
- Font buttonFont2 = new Font("Arial", Font.BOLD, 16);
- Font buttonFont3 = new Font("Arial",Font.BOLD, 11);
- JLabel lbl1 = new JLabel("Hello There!");
- JLabel lbl2 = new JLabel("Add Your To-Do-List Here.");
- JLabel lbl3 = new JLabel("CHOOSE A CATEGORY FOR YOUR LIST");
- JButton btn0 = new JButton("+");
- JButton btn1 = new JButton("PERSONAL STUFF");
- JButton btn2 = new JButton("WORK PROJECTS");
- JButton btn3 = new JButton("GROCERY LIST");
- JButton btn4 = new JButton("SCHOOL WORK");
- JButton btn5 = new JButton("EVENTS AND OCCASIONS");
- public UI()
- {
- super("TO-DO-LIST APPLICATION");
- setDefaultLookAndFeelDecorated(true);
- con.setLayout(new GridLayout(1,2));
- mainpnl1.setLayout(null);
- mainpnl1.setBackground(new Color(81,23,43));
- mainpnl2.setForeground(new Color(56,23,43));
- mainpnl2.setBackground(new Color(56,23,43));
- pnl2.add(lbl3);
- pnl2.add(btn1);
- pnl2.add(btn2);
- pnl2.add(btn3);
- pnl2.add(btn4);
- pnl2.add(btn5);
- pnl1.setBackground(new Color(56,23,43));
- pnl2.setBackground(new Color(56,23,43));
- pnl1.setBounds(40,90,240,200);
- mainpnl2.setLayout(null);
- pnl2.setBounds(15,90,290,200);
- btn0.setBounds(350,230,150,150);
- btn0.setFont(buttonFont1);
- btn1.setFont(buttonFont2);
- btn2.setFont(buttonFont2);
- btn3.setFont(buttonFont2);
- btn4.setFont(buttonFont2);
- btn5.setFont(buttonFont2);
- btn1.setSize(30,70);
- btn2.setSize(30,70);
- btn3.setSize(30,70);
- btn4.setSize(30,70);
- btn5.setSize(30,70);
- lbl1.setFont(myFont1);
- lbl1.setForeground(Color.WHITE);
- lbl1.setBounds(50,50,50,50);
- lbl2.setFont(myFont2);
- lbl2.setBounds(100,100,100,100);
- lbl2.setForeground(Color.WHITE);
- lbl3.setFont(myFont3);
- lbl3.setForeground(Color.WHITE);
- btn0.setBounds(150,230,50,50);
- btn0.addActionListener(this);
- btn1.addActionListener(this);
- btn2.addActionListener(this);
- btn3.addActionListener(this);
- btn4.addActionListener(this);
- btn5.addActionListener(this);
- pnl1.add(lbl1);
- pnl1.add(lbl2);
- pnl1.add(btn0);
- mainpnl1.add(pnl1);
- pnl2.setVisible(false);
- mainpnl2.add(pnl2);
- con.add(mainpnl1);
- con.add(mainpnl2);
- }
- @Override
- public void actionPerformed(ActionEvent e)
- {
- Object source = e.getSource();
- if(source == btn0)
- {
- pnl2.setVisible(true);
- }
- if(source == btn1)
- {
- JFrame frame1 = new JFrame("PERSONAL STUFF");
- JPanel panel1 = new JPanel();
- JTable table1 = new JTable();
- JTextField txtfield1 = new JTextField();
- JScrollPane pane1 = new JScrollPane(table1);
- DefaultTableModel a = new DefaultTableModel();
- pane1.setBounds(0,0,300,150);
- JButton btnadd = new JButton("ADD");
- JButton btndlt = new JButton("DELETE");
- JButton btnmdfy = new JButton("MODIFY");
- //SPACE PARA ADD MODIFY DELETE//
- Object[] columns = {"YOUR TO-DO-LISTS"};
- a.setColumnIdentifiers(columns);
- table1.setBackground(Color.LIGHT_GRAY);
- table1.setForeground(Color.black);
- Font font = new Font("",1,22);
- table1.setFont(font);
- table1.setRowHeight(30);
- txtfield1.setBounds(40,40,40,40);
- Object[] row = new Object[0];
- btnadd.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e) {
- a.addRow(row);
- }
- });
- btndlt.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e) {
- int i = table1.getSelectedRow();
- if(i >= 0){
- a.removeRow(i);
- }
- else{
- System.out.println("Failed to Delete");
- }
- }
- });
- table1.addMouseListener(new MouseAdapter(){
- @Override
- public void mouseClicked(MouseEvent e){
- int i = table1.getSelectedRow();
- txtfield1.setText(a.getValueAt(i, 0).toString());
- }
- });
- btnmdfy.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent e) {
- int i = table1.getSelectedRow();
- if(i >= 0)
- {
- a.setValueAt(txtfield1.getText(), i, 0);
- }
- else{
- System.out.println("Failed to Modify!");
- }
- }
- });
- txtfield1.setBounds(30,100,100,100);
- txtfield1.setSize(230, 30);
- panel1.setLayout(null);
- panel1.setBounds(90,100,90,100);
- panel1.setBackground(new Color(10,10,10));
- // frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE);
- frame1.setDefaultLookAndFeelDecorated(true);
- frame1.setSize(300,400);
- btnadd.setFont(buttonFont3);
- btndlt.setFont(buttonFont3);
- btnmdfy.setFont(buttonFont3);
- btnadd.setBounds(15,30,80,30);
- btndlt.setBounds(105,30,80,30);
- btnmdfy.setBounds(195,30,80,30);
- frame1.setVisible(true);
- panel1.add(btnadd);
- panel1.add(btndlt);
- panel1.add(btnmdfy);
- frame1.add(panel1);
- panel1.add(txtfield1);
- panel1.add(table1);
- }
- if(source == btn2)
- {
- JFrame frame2 = new JFrame("WORK PROJECTS");
- JPanel panel2 = new JPanel();
- JTextField txtfield2 = new JTextField();
- JTable table1 = new JTable();
- JButton btnadd = new JButton("ADD");
- JButton btndlt = new JButton("DELETE");
- JButton btnmdfy = new JButton("MODIFY");
- txtfield2.setBounds(30,100,100,100);
- txtfield2.setSize(230, 30);
- panel2.setLayout(null);
- panel2.setBounds(90,100,90,100);
- panel2.setBackground(new Color(10,10,10));
- //setDefaultCloseOperation(frame2.EXIT_ON_CLOSE);
- frame2.setDefaultLookAndFeelDecorated(true);
- frame2.setSize(300,400);
- btnadd.setFont(buttonFont3);
- btndlt.setFont(buttonFont3);
- btnmdfy.setFont(buttonFont3);
- btnadd.setBounds(15,30,80,30);
- btndlt.setBounds(105,30,80,30);
- btnmdfy.setBounds(195,30,80,30);
- frame2.setVisible(true);
- panel2.add(btnadd);
- panel2.add(btndlt);
- panel2.add(btnmdfy);
- frame2.add(panel2);
- panel2.add(txtfield2);
- }
- if(source == btn3)
- {
- JFrame frame3 = new JFrame("GROCERY LIST");
- JPanel panel3 = new JPanel();
- JTextField txtfield3 = new JTextField();
- JTable table1 = new JTable();
- JButton btnadd = new JButton("ADD");
- JButton btndlt = new JButton("DELETE");
- JButton btnmdfy = new JButton("MODIFY");
- txtfield3.setBounds(30,100,100,100);
- txtfield3.setSize(230, 30);
- panel3.setLayout(null);
- panel3.setBounds(90,100,90,100);
- panel3.setBackground(new Color(10,10,10));
- //setDefaultCloseOperation(frame3.EXIT_ON_CLOSE);
- frame3.setDefaultLookAndFeelDecorated(true);
- frame3.setSize(300,400);
- btnadd.setFont(buttonFont3);
- btndlt.setFont(buttonFont3);
- btnmdfy.setFont(buttonFont3);
- btnadd.setBounds(15,30,80,30);
- btndlt.setBounds(105,30,80,30);
- btnmdfy.setBounds(195,30,80,30);
- frame3.setVisible(true);
- panel3.add(btnadd);
- panel3.add(btndlt);
- panel3.add(btnmdfy);
- frame3.add(panel3);
- panel3.add(txtfield3);
- }
- if(source == btn4)
- {
- JFrame frame4 = new JFrame("SCHOOL WORK");
- JPanel panel4 = new JPanel();
- JTextField txtfield4 = new JTextField();
- JButton btnadd = new JButton("ADD");
- JButton btndlt = new JButton("DELETE");
- JButton btnmdfy = new JButton("MODIFY");
- txtfield4.setBounds(30,100,100,100);
- txtfield4.setSize(230, 30);
- panel4.setLayout(null);
- panel4.setBounds(90,100,90,100);
- panel4.setBackground(new Color(10,10,10));
- //setDefaultCloseOperation(frame4.EXIT_ON_CLOSE);
- frame4.setDefaultLookAndFeelDecorated(true);
- frame4.setSize(300,400);
- btnadd.setFont(buttonFont3);
- btndlt.setFont(buttonFont3);
- btnmdfy.setFont(buttonFont3);
- btnadd.setBounds(15,30,80,30);
- btndlt.setBounds(105,30,80,30);
- btnmdfy.setBounds(195,30,80,30);
- frame4.setVisible(true);
- panel4.add(btnadd);
- panel4.add(btndlt);
- panel4.add(btnmdfy);
- frame4.add(panel4);
- panel4.add(txtfield4);
- }
- if(source == btn5)
- {
- JFrame frame5 = new JFrame("EVENTS AND OCCASIONS");
- JPanel panel5 = new JPanel();
- JTextField txtfield5 = new JTextField();
- JButton btnadd = new JButton("ADD");
- JButton btndlt = new JButton("DELETE");
- JButton btnmdfy = new JButton("MODIFY");
- txtfield5.setBounds(30,100,100,100);
- txtfield5.setSize(230, 30);
- panel5.setLayout(null);
- panel5.setBounds(90,100,90,100);
- panel5.setBackground(new Color(10,10,10));
- //setDefaultCloseOperation(frame5.EXIT_ON_CLOSE);
- frame5.setDefaultLookAndFeelDecorated(true);
- frame5.setSize(300,400);
- btnadd.setFont(buttonFont3);
- btndlt.setFont(buttonFont3);
- btnmdfy.setFont(buttonFont3);
- btnadd.setBounds(15,30,80,30);
- btndlt.setBounds(105,30,80,30);
- btnmdfy.setBounds(195,30,80,30);
- frame5.setVisible(true);
- panel5.add(btnadd);
- panel5.add(btndlt);
- panel5.add(btnmdfy);
- frame5.add(panel5);
- panel5.add(txtfield5);
- btnadd.addActionListener(this);
- }
- invalidate();
- validate();
- }
- public void itemStateChanged(ItemEvent e)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement