Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.95 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. public class Test {
  3.  
  4.  
  5.  
  6. public static void main(String[] args) {
  7.  
  8. menu gui = new menu();
  9. gui.setTitle("Simple Menu");
  10. gui.setSize(800,600);
  11. gui.setLocation(300,200);
  12. gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13. gui.setResizable(false);
  14. gui.setVisible(true);
  15.  
  16. }
  17.  
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. import javax.swing.*;
  29. import java.awt.event.*;
  30. import java.awt.*;
  31. import java.io.IOException;
  32. import java.io.RandomAccessFile;
  33.  
  34. public class menu extends JFrame implements ActionListener
  35.  
  36. {
  37.  
  38. private Container cn;
  39. private JMenuBar jmb;
  40. private JMenu mnuPerson, mnuSystem, mnuDisplay,mnuReport;
  41. private JMenuItem mnuItemAdd, mnuItemDisplayAll,mnuItemDisplayByID,mnuItemDisplayByMake,mnuItemExit;
  42. private JMenuItem mnuItemUpdate, mnuItemDelete,mnuItemReportAll,mnuItemReportMake;
  43. Absolute1 my = null;
  44.  
  45.  
  46.  
  47. public menu()
  48. {
  49. cn = getContentPane();
  50. cn.setBackground(Color.blue);
  51.  
  52. jmb = new JMenuBar();
  53.  
  54. mnuPerson = new JMenu("Car!");
  55. mnuPerson.setFont(new Font("Serif", Font.BOLD, 24));
  56.  
  57. mnuItemAdd = new JMenuItem("Add Car!");
  58. mnuItemAdd.setFont(new Font("Serif", Font.BOLD, 24));
  59. mnuItemAdd.addActionListener(this);
  60. mnuPerson.add(mnuItemAdd);
  61.  
  62.  
  63.  
  64.  
  65. mnuDisplay = new JMenu("Display!");
  66. mnuDisplay.setFont(new Font("Serif", Font.BOLD, 24));
  67.  
  68. mnuItemDisplayAll = new JMenuItem("Display All!");
  69. mnuItemDisplayAll.setFont(new Font("Serif", Font.BOLD, 24));
  70. mnuItemDisplayAll.addActionListener(this);
  71. mnuDisplay.add(mnuItemDisplayAll);
  72.  
  73. mnuItemDisplayByID = new JMenuItem("Display By Reg!");
  74. mnuItemDisplayByID.setFont(new Font("Serif", Font.BOLD, 24));
  75. mnuItemDisplayByID.addActionListener(this);
  76. mnuDisplay.add(mnuItemDisplayByID);
  77.  
  78. mnuItemDisplayByMake = new JMenuItem("Display By Make!");
  79. mnuItemDisplayByMake.setFont(new Font("Serif", Font.BOLD, 24));
  80. mnuItemDisplayByMake.addActionListener(this);
  81. mnuDisplay.add(mnuItemDisplayByMake);
  82.  
  83. mnuPerson.add(mnuDisplay);
  84.  
  85. mnuItemUpdate = new JMenuItem("Update");
  86. mnuItemUpdate.setFont(new Font("Serif", Font.BOLD, 24));
  87. mnuItemUpdate.addActionListener(this);
  88. mnuPerson.add(mnuItemUpdate);
  89.  
  90. mnuItemDelete = new JMenuItem("Delete");
  91. mnuItemDelete.setFont(new Font("Serif", Font.BOLD, 24));
  92. mnuItemDelete.addActionListener(this);
  93. mnuPerson.add(mnuItemDelete);
  94.  
  95.  
  96. mnuReport = new JMenu("Reports!");
  97. mnuReport.setFont(new Font("Serif", Font.BOLD, 24));
  98. mnuItemReportAll = new JMenuItem("Report all");
  99. mnuItemReportAll.setFont(new Font("Serif", Font.BOLD, 24));
  100. mnuItemReportAll.addActionListener(this);
  101. mnuReport.add(mnuItemReportAll);
  102.  
  103. mnuItemReportMake = new JMenuItem("Make");
  104. mnuItemReportMake.setFont(new Font("Serif", Font.BOLD, 24));
  105. mnuItemReportMake.addActionListener(this);
  106. mnuReport.add(mnuItemReportMake);
  107.  
  108.  
  109.  
  110.  
  111. mnuSystem = new JMenu("System!");
  112. mnuSystem.setFont(new Font("Serif", Font.BOLD, 24));
  113.  
  114. mnuItemExit = new JMenuItem("Exit!");
  115. mnuItemExit.setFont(new Font("Serif", Font.BOLD, 24));
  116. mnuItemExit.addActionListener(this);
  117. mnuSystem.add(mnuItemExit);
  118.  
  119. jmb.add(mnuPerson);
  120. jmb.add(mnuReport);
  121. jmb.add(mnuSystem);
  122.  
  123. setJMenuBar(jmb);
  124. }
  125.  
  126.  
  127. public void windowDeactivated(WindowEvent arg0) {
  128. JOptionPane.showMessageDialog(null, "Window Deactivated");
  129. }
  130.  
  131.  
  132. public void actionPerformed(ActionEvent e)
  133. {
  134. if(e.getActionCommand().equalsIgnoreCase("Exit!"))System.exit(0);
  135.  
  136. if(e.getActionCommand().equalsIgnoreCase("Add car!"))
  137. {
  138.  
  139. if(my == null){
  140. my = new Absolute1();
  141. my.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  142. my.setVisible(true);
  143. my.setSize(800, 600);
  144. my.addWindowListener(null);
  145. my.setResizable(false);
  146. }
  147.  
  148. if (my.isVisible())
  149. {
  150. my.setVisible(false);
  151. }
  152. my.setVisible(true);
  153. Absolute1 my = null;
  154.  
  155.  
  156.  
  157. }
  158.  
  159.  
  160. if(e.getActionCommand().equalsIgnoreCase("Display All!"))
  161. {
  162. JOptionPane.showMessageDialog(null, "DisplayAll");
  163. }
  164.  
  165. if(e.getActionCommand().equalsIgnoreCase("Report all"))
  166. {
  167. JOptionPane.showMessageDialog(null, "ReportAll");
  168. }
  169.  
  170. if(e.getActionCommand().equalsIgnoreCase("Make"))
  171. {
  172. JOptionPane.showMessageDialog(null, "Make");
  173. }
  174.  
  175. if(e.getActionCommand().equalsIgnoreCase("Display By make!"))
  176. {
  177. JOptionPane.showMessageDialog(null, "make");
  178. }
  179.  
  180. if(e.getActionCommand().equalsIgnoreCase("Display By reg!"))
  181. {
  182. JOptionPane.showMessageDialog(null, "reg");
  183. }
  184. if(e.getActionCommand().equalsIgnoreCase("update"))
  185. {
  186. JOptionPane.showMessageDialog(null, "Update");
  187. }
  188.  
  189. if(e.getActionCommand().equalsIgnoreCase("Delete"))
  190. {
  191. JOptionPane.showMessageDialog(null, "delete!");
  192. }
  193. }
  194.  
  195. }
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205. import javax.swing.*;
  206.  
  207. import java.awt.*;
  208. import java.awt.event.*;
  209. import java.io.EOFException;
  210. import java.io.FileNotFoundException;
  211. import java.io.IOException;
  212. import java.io.RandomAccessFile;
  213. import java.util.*;
  214.  
  215. public class Absolute1 extends JFrame implements ActionListener,WindowListener, MouseListener{
  216. private Container cn;
  217. private JLabel lbl;
  218. private JTextField txtReg, txtMake,txtModel,txtSize,txtcost;
  219. private JComboBox cmbMonth,cmbYear;
  220. private JButton btnAdd;
  221. RandomAccessFile rd = null;
  222. private String reg, make, model, size, month;
  223. private int year;
  224. private double cost;
  225. private JMenuBar jmb;
  226. private JMenu mnuSystem;
  227. private JMenuItem mnuItemExit;
  228. int[] years = {2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011};
  229.  
  230. public Absolute1() {
  231.  
  232. cn = getContentPane();
  233. cn.setLayout(null);
  234. cn.addMouseListener(this);
  235. txtReg = new JTextField("Input your Car reg!");
  236. txtReg.addMouseListener(this);
  237. txtReg.setBounds(500, 200, 200, 20);
  238. txtMake = new JTextField("Input your make!");
  239. txtMake.addMouseListener(this);
  240. txtMake.setBounds(500, 250, 200, 20);
  241. txtModel = new JTextField("Input your model!");
  242. txtModel.addMouseListener(this);
  243. txtModel.setBounds(500, 300, 200, 20);
  244. txtSize = new JTextField();
  245. cn.add(txtReg);
  246. cn.add(txtMake);
  247. cn.add(txtModel);
  248. cn.add(txtSize);
  249. JButton btnAdd = new JButton("Save!");
  250. btnAdd.addActionListener(this);
  251. btnAdd.setBounds(50, 500, 700, 25);
  252. cn.add(btnAdd);
  253. addWindowListener(this);
  254. jmb = new JMenuBar();
  255. cmbYear = new JComboBox();
  256.  
  257. cmbYear.setBounds( 400, 25, 260, 20 );
  258. cn.add(cmbYear);
  259.  
  260. for (int u = 0;u<10;u++)cmbYear.addItem(years[u]);
  261.  
  262.  
  263. mnuSystem = new JMenu("System!");
  264. mnuSystem.setFont(new Font("Serif", Font.BOLD, 24));
  265. mnuItemExit = new JMenuItem("Exit!");
  266. mnuItemExit.setFont(new Font("Serif", Font.BOLD, 24));
  267. mnuItemExit.addActionListener(this);
  268. mnuSystem.add(mnuItemExit);
  269. jmb.add(mnuSystem);
  270. setJMenuBar(jmb);
  271.  
  272. }
  273.  
  274.  
  275. public void actionPerformed(ActionEvent e) {
  276. if(e.getActionCommand().equalsIgnoreCase("Exit!"))
  277. {
  278. this.setVisible(false);
  279. }
  280.  
  281.  
  282.  
  283. if(e.getActionCommand().equalsIgnoreCase("Save!"))
  284. {
  285. String wat = null;
  286. try {
  287. rd = new RandomAccessFile("this","rw");
  288. } catch (FileNotFoundException e2) {
  289. // TODO Auto-generated catch block
  290. e2.printStackTrace();
  291. }
  292. try {
  293. if(rd.length()<1)
  294. {
  295.  
  296. }
  297. else
  298. {
  299. try {
  300.  
  301.  
  302.  
  303. wat = wat + rd.readUTF();
  304. wat = wat + rd.readUTF();
  305. wat = wat + rd.readInt();
  306.  
  307. } catch (IOException e1) {
  308. // TODO Auto-generated catch block
  309. e1.printStackTrace();
  310. }
  311. }
  312. } catch (IOException e2) {
  313. // TODO Auto-generated catch block
  314. e2.printStackTrace();
  315. }
  316. try {
  317.  
  318.  
  319.  
  320. rd.seek(rd.length());
  321.  
  322. reg = txtReg.getText();
  323. reg = tools.pad(reg,10);
  324. rd.writeUTF(reg);
  325.  
  326. make = "abcdefghijklmopqrstuvwxyz";
  327. make = tools.pad(make,20);
  328. rd.writeUTF(make);
  329.  
  330. model = "qwertyuiopasdfghjklzxcvbnm";
  331. model = tools.pad(model,20);
  332. rd.writeUTF(model);
  333.  
  334. rd.writeInt(years[cmbYear.getItemCount()]);
  335. rd.close();
  336.  
  337. } catch (FileNotFoundException e1) {
  338. JOptionPane.showMessageDialog(null, "FUCKED");
  339. } catch (IOException e1) {
  340. // TODO Auto-generated catch block
  341. e1.printStackTrace();
  342. }
  343.  
  344. }
  345.  
  346. }
  347.  
  348.  
  349. public void windowClosing(WindowEvent e) {
  350.  
  351. }
  352.  
  353. @Override
  354. public void windowActivated(WindowEvent arg0) {
  355.  
  356. }
  357.  
  358. @Override
  359. public void windowDeiconified(WindowEvent arg0) {
  360. // TODO Auto-generated method stub
  361.  
  362. }
  363.  
  364. @Override
  365. public void windowIconified(WindowEvent arg0) {
  366. // TODO Auto-generated method stub
  367.  
  368. }
  369.  
  370. @Override
  371. public void windowOpened(WindowEvent arg0) {
  372. // TODO Auto-generated method stub
  373.  
  374. }
  375.  
  376. @Override
  377. public void windowClosed(WindowEvent e) {
  378.  
  379. }
  380.  
  381. @Override
  382. public void windowDeactivated(WindowEvent e) {
  383. if(rd!=null)
  384. {
  385. try {
  386. rd.close();
  387. } catch (IOException e1) {
  388. // TODO Auto-generated catch block
  389. JOptionPane.showMessageDialog(null, "FUCKYOUSHIT");
  390. this.setEnabled(false);
  391. }
  392. }
  393. }
  394.  
  395.  
  396. @Override
  397. public void mouseClicked(MouseEvent e1) {
  398.  
  399.  
  400.  
  401. if(e1.getComponent()==txtReg)
  402. {
  403. txtReg.setText("");
  404. }
  405.  
  406. if(e1.getComponent()==txtMake)
  407. {
  408. txtMake.setText("");
  409. }
  410.  
  411. if(e1.getComponent()==txtModel)
  412. {
  413. txtModel.setText("");
  414. }
  415.  
  416. }
  417.  
  418.  
  419. @Override
  420. public void mouseEntered(MouseEvent arg0) {
  421. // TODO Auto-generated method stub
  422.  
  423. }
  424.  
  425.  
  426. @Override
  427. public void mouseExited(MouseEvent arg0) {
  428. // TODO Auto-generated method stub
  429.  
  430. }
  431.  
  432.  
  433. @Override
  434. public void mousePressed(MouseEvent arg0) {
  435. // TODO Auto-generated method stub
  436.  
  437. }
  438.  
  439.  
  440. @Override
  441. public void mouseReleased(MouseEvent arg0) {
  442. // TODO Auto-generated method stub
  443.  
  444. }
  445.  
  446.  
  447. }
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458. public class tools {
  459.  
  460. public static String pad(String s, int max)
  461. {
  462. if (s.length()<max)
  463. {
  464. for(int x=s.length();x<max;x++)
  465. {
  466. s = s + " ";
  467. }
  468. }
  469. if(s.length()>max)
  470. {
  471. s = s.substring(0, max);
  472. }
  473.  
  474. return s;
  475.  
  476. }
  477.  
  478. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement