Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.03 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.awt.Color.*;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.MouseAdapter;
  7. import java.awt.event.MouseEvent;
  8. import javax.swing.JButton;
  9. import javax.swing.JScrollPane;
  10. import javax.swing.JTextField;
  11. import javax.swing.JTable;
  12. import javax.swing.table.DefaultTableModel;
  13.  
  14.  
  15.  
  16. public class UI extends JFrame implements ActionListener, ItemListener
  17. {
  18. final int SIZE = 400;
  19.  
  20. JFrame frame = new JFrame();
  21. Container con = getContentPane();
  22.  
  23. JPanel mainpnl1 = new JPanel();
  24. JPanel mainpnl2 = new JPanel();
  25.  
  26. JPanel pnl1 = new JPanel();
  27. JPanel pnl2 = new JPanel();
  28. Font myFont1 = new Font("Times New Roman", Font.BOLD, 25);
  29. Font myFont2 = new Font("Times New Roman", Font.BOLD,20);
  30. Font myFont3 = new Font("Times New Roman", Font.BOLD,14);
  31. Font buttonFont1 = new Font("Arial", Font.BOLD, 24);
  32. Font buttonFont2 = new Font("Arial", Font.BOLD, 16);
  33. Font buttonFont3 = new Font("Arial",Font.BOLD, 11);
  34.  
  35. JLabel lbl1 = new JLabel("Hello There!");
  36. JLabel lbl2 = new JLabel("Add Your To-Do-List Here.");
  37. JLabel lbl3 = new JLabel("CHOOSE A CATEGORY FOR YOUR LIST");
  38.  
  39. JButton btn0 = new JButton("+");
  40. JButton btn1 = new JButton("PERSONAL STUFF");
  41. JButton btn2 = new JButton("WORK PROJECTS");
  42. JButton btn3 = new JButton("GROCERY LIST");
  43. JButton btn4 = new JButton("SCHOOL WORK");
  44. JButton btn5 = new JButton("EVENTS AND OCCASIONS");
  45.  
  46. public UI()
  47. {
  48. super("TO-DO-LIST APPLICATION");
  49. setDefaultLookAndFeelDecorated(true);
  50. con.setLayout(new GridLayout(1,2));
  51.  
  52. mainpnl1.setLayout(null);
  53. mainpnl1.setBackground(new Color(81,23,43));
  54. mainpnl2.setForeground(new Color(56,23,43));
  55. mainpnl2.setBackground(new Color(56,23,43));
  56.  
  57. pnl2.add(lbl3);
  58. pnl2.add(btn1);
  59. pnl2.add(btn2);
  60. pnl2.add(btn3);
  61. pnl2.add(btn4);
  62. pnl2.add(btn5);
  63.  
  64. pnl1.setBackground(new Color(56,23,43));
  65. pnl2.setBackground(new Color(56,23,43));
  66.  
  67. pnl1.setBounds(40,90,240,200);
  68. mainpnl2.setLayout(null);
  69. pnl2.setBounds(15,90,290,200);
  70.  
  71. btn0.setBounds(350,230,150,150);
  72. btn0.setFont(buttonFont1);
  73.  
  74. btn1.setFont(buttonFont2);
  75. btn2.setFont(buttonFont2);
  76. btn3.setFont(buttonFont2);
  77. btn4.setFont(buttonFont2);
  78. btn5.setFont(buttonFont2);
  79.  
  80. btn1.setSize(30,70);
  81. btn2.setSize(30,70);
  82. btn3.setSize(30,70);
  83. btn4.setSize(30,70);
  84. btn5.setSize(30,70);
  85.  
  86.  
  87. lbl1.setFont(myFont1);
  88. lbl1.setForeground(Color.WHITE);
  89. lbl1.setBounds(50,50,50,50);
  90. lbl2.setFont(myFont2);
  91. lbl2.setBounds(100,100,100,100);
  92. lbl2.setForeground(Color.WHITE);
  93. lbl3.setFont(myFont3);
  94. lbl3.setForeground(Color.WHITE);
  95.  
  96. btn0.setBounds(150,230,50,50);
  97. btn0.addActionListener(this);
  98.  
  99. btn1.addActionListener(this);
  100. btn2.addActionListener(this);
  101. btn3.addActionListener(this);
  102. btn4.addActionListener(this);
  103. btn5.addActionListener(this);
  104.  
  105.  
  106. pnl1.add(lbl1);
  107. pnl1.add(lbl2);
  108. pnl1.add(btn0);
  109.  
  110. mainpnl1.add(pnl1);
  111. pnl2.setVisible(false);
  112. mainpnl2.add(pnl2);
  113.  
  114.  
  115. con.add(mainpnl1);
  116. con.add(mainpnl2);
  117.  
  118.  
  119. }
  120.  
  121. @Override
  122. public void actionPerformed(ActionEvent e)
  123. {
  124. Object source = e.getSource();
  125.  
  126. if(source == btn0)
  127. {
  128. pnl2.setVisible(true);
  129. }
  130.  
  131.  
  132. if(source == btn1)
  133. {
  134. JFrame frame1 = new JFrame("PERSONAL STUFF");
  135. JPanel panel1 = new JPanel();
  136. JTable table1 = new JTable();
  137. JTextField txtfield1 = new JTextField();
  138. JScrollPane pane1 = new JScrollPane(table1);
  139. DefaultTableModel a = new DefaultTableModel();
  140.  
  141. pane1.setBounds(0,0,300,150);
  142.  
  143. JButton btnadd = new JButton("ADD");
  144. JButton btndlt = new JButton("DELETE");
  145. JButton btnmdfy = new JButton("MODIFY");
  146.  
  147.  
  148. //SPACE PARA ADD MODIFY DELETE//
  149.  
  150. Object[] columns = {"YOUR TO-DO-LISTS"};
  151. a.setColumnIdentifiers(columns);
  152. table1.setBackground(Color.LIGHT_GRAY);
  153. table1.setForeground(Color.black);
  154. Font font = new Font("",1,22);
  155. table1.setFont(font);
  156. table1.setRowHeight(30);
  157.  
  158. txtfield1.setBounds(40,40,40,40);
  159.  
  160.  
  161. Object[] row = new Object[0];
  162.  
  163.  
  164. btnadd.addActionListener(new ActionListener(){
  165.  
  166. @Override
  167. public void actionPerformed(ActionEvent e) {
  168.  
  169.  
  170.  
  171. a.addRow(row);
  172. }
  173. });
  174.  
  175.  
  176. btndlt.addActionListener(new ActionListener(){
  177.  
  178. @Override
  179. public void actionPerformed(ActionEvent e) {
  180.  
  181.  
  182. int i = table1.getSelectedRow();
  183. if(i >= 0){
  184.  
  185. a.removeRow(i);
  186. }
  187. else{
  188. System.out.println("Failed to Delete");
  189. }
  190. }
  191. });
  192.  
  193.  
  194. table1.addMouseListener(new MouseAdapter(){
  195.  
  196. @Override
  197. public void mouseClicked(MouseEvent e){
  198.  
  199.  
  200. int i = table1.getSelectedRow();
  201.  
  202. txtfield1.setText(a.getValueAt(i, 0).toString());
  203.  
  204. }
  205. });
  206.  
  207. btnmdfy.addActionListener(new ActionListener(){
  208.  
  209. @Override
  210. public void actionPerformed(ActionEvent e) {
  211.  
  212.  
  213. int i = table1.getSelectedRow();
  214.  
  215. if(i >= 0)
  216. {
  217. a.setValueAt(txtfield1.getText(), i, 0);
  218. }
  219. else{
  220. System.out.println("Failed to Modify!");
  221. }
  222. }
  223. });
  224.  
  225. txtfield1.setBounds(30,100,100,100);
  226. txtfield1.setSize(230, 30);
  227. panel1.setLayout(null);
  228. panel1.setBounds(90,100,90,100);
  229. panel1.setBackground(new Color(10,10,10));
  230.  
  231. // frame1.setDefaultCloseOperation(frame1.EXIT_ON_CLOSE);
  232. frame1.setDefaultLookAndFeelDecorated(true);
  233. frame1.setSize(300,400);
  234. btnadd.setFont(buttonFont3);
  235. btndlt.setFont(buttonFont3);
  236. btnmdfy.setFont(buttonFont3);
  237. btnadd.setBounds(15,30,80,30);
  238. btndlt.setBounds(105,30,80,30);
  239. btnmdfy.setBounds(195,30,80,30);
  240. frame1.setVisible(true);
  241.  
  242. panel1.add(btnadd);
  243. panel1.add(btndlt);
  244. panel1.add(btnmdfy);
  245. frame1.add(panel1);
  246. panel1.add(txtfield1);
  247. panel1.add(table1);
  248.  
  249.  
  250. }
  251.  
  252. if(source == btn2)
  253. {
  254. JFrame frame2 = new JFrame("WORK PROJECTS");
  255. JPanel panel2 = new JPanel();
  256. JTextField txtfield2 = new JTextField();
  257. JTable table1 = new JTable();
  258.  
  259.  
  260. JButton btnadd = new JButton("ADD");
  261. JButton btndlt = new JButton("DELETE");
  262. JButton btnmdfy = new JButton("MODIFY");
  263.  
  264. txtfield2.setBounds(30,100,100,100);
  265. txtfield2.setSize(230, 30);
  266. panel2.setLayout(null);
  267. panel2.setBounds(90,100,90,100);
  268. panel2.setBackground(new Color(10,10,10));
  269. //setDefaultCloseOperation(frame2.EXIT_ON_CLOSE);
  270. frame2.setDefaultLookAndFeelDecorated(true);
  271. frame2.setSize(300,400);
  272. btnadd.setFont(buttonFont3);
  273. btndlt.setFont(buttonFont3);
  274. btnmdfy.setFont(buttonFont3);
  275. btnadd.setBounds(15,30,80,30);
  276. btndlt.setBounds(105,30,80,30);
  277. btnmdfy.setBounds(195,30,80,30);
  278. frame2.setVisible(true);
  279.  
  280. panel2.add(btnadd);
  281. panel2.add(btndlt);
  282. panel2.add(btnmdfy);
  283. frame2.add(panel2);
  284. panel2.add(txtfield2);
  285.  
  286. }
  287. if(source == btn3)
  288. {
  289. JFrame frame3 = new JFrame("GROCERY LIST");
  290. JPanel panel3 = new JPanel();
  291. JTextField txtfield3 = new JTextField();
  292. JTable table1 = new JTable();
  293.  
  294.  
  295. JButton btnadd = new JButton("ADD");
  296. JButton btndlt = new JButton("DELETE");
  297. JButton btnmdfy = new JButton("MODIFY");
  298.  
  299. txtfield3.setBounds(30,100,100,100);
  300. txtfield3.setSize(230, 30);
  301. panel3.setLayout(null);
  302. panel3.setBounds(90,100,90,100);
  303. panel3.setBackground(new Color(10,10,10));
  304. //setDefaultCloseOperation(frame3.EXIT_ON_CLOSE);
  305. frame3.setDefaultLookAndFeelDecorated(true);
  306. frame3.setSize(300,400);
  307. btnadd.setFont(buttonFont3);
  308. btndlt.setFont(buttonFont3);
  309. btnmdfy.setFont(buttonFont3);
  310. btnadd.setBounds(15,30,80,30);
  311. btndlt.setBounds(105,30,80,30);
  312. btnmdfy.setBounds(195,30,80,30);
  313. frame3.setVisible(true);
  314.  
  315. panel3.add(btnadd);
  316. panel3.add(btndlt);
  317. panel3.add(btnmdfy);
  318. frame3.add(panel3);
  319. panel3.add(txtfield3);
  320.  
  321. }
  322. if(source == btn4)
  323. {
  324. JFrame frame4 = new JFrame("SCHOOL WORK");
  325. JPanel panel4 = new JPanel();
  326. JTextField txtfield4 = new JTextField();
  327.  
  328.  
  329. JButton btnadd = new JButton("ADD");
  330. JButton btndlt = new JButton("DELETE");
  331. JButton btnmdfy = new JButton("MODIFY");
  332.  
  333. txtfield4.setBounds(30,100,100,100);
  334. txtfield4.setSize(230, 30);
  335. panel4.setLayout(null);
  336. panel4.setBounds(90,100,90,100);
  337. panel4.setBackground(new Color(10,10,10));
  338. //setDefaultCloseOperation(frame4.EXIT_ON_CLOSE);
  339. frame4.setDefaultLookAndFeelDecorated(true);
  340. frame4.setSize(300,400);
  341. btnadd.setFont(buttonFont3);
  342. btndlt.setFont(buttonFont3);
  343. btnmdfy.setFont(buttonFont3);
  344. btnadd.setBounds(15,30,80,30);
  345. btndlt.setBounds(105,30,80,30);
  346. btnmdfy.setBounds(195,30,80,30);
  347. frame4.setVisible(true);
  348.  
  349. panel4.add(btnadd);
  350. panel4.add(btndlt);
  351. panel4.add(btnmdfy);
  352. frame4.add(panel4);
  353. panel4.add(txtfield4);
  354.  
  355. }
  356. if(source == btn5)
  357. {
  358. JFrame frame5 = new JFrame("EVENTS AND OCCASIONS");
  359. JPanel panel5 = new JPanel();
  360. JTextField txtfield5 = new JTextField();
  361.  
  362.  
  363. JButton btnadd = new JButton("ADD");
  364. JButton btndlt = new JButton("DELETE");
  365. JButton btnmdfy = new JButton("MODIFY");
  366.  
  367. txtfield5.setBounds(30,100,100,100);
  368. txtfield5.setSize(230, 30);
  369. panel5.setLayout(null);
  370. panel5.setBounds(90,100,90,100);
  371. panel5.setBackground(new Color(10,10,10));
  372. //setDefaultCloseOperation(frame5.EXIT_ON_CLOSE);
  373. frame5.setDefaultLookAndFeelDecorated(true);
  374. frame5.setSize(300,400);
  375. btnadd.setFont(buttonFont3);
  376. btndlt.setFont(buttonFont3);
  377. btnmdfy.setFont(buttonFont3);
  378. btnadd.setBounds(15,30,80,30);
  379. btndlt.setBounds(105,30,80,30);
  380. btnmdfy.setBounds(195,30,80,30);
  381. frame5.setVisible(true);
  382.  
  383. panel5.add(btnadd);
  384. panel5.add(btndlt);
  385. panel5.add(btnmdfy);
  386. frame5.add(panel5);
  387. panel5.add(txtfield5);
  388. btnadd.addActionListener(this);
  389. }
  390. invalidate();
  391. validate();
  392. }
  393. public void itemStateChanged(ItemEvent e)
  394. {
  395.  
  396. }
  397.  
  398. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement