Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- public class Test {
- public static void main(String[] args) {
- menu gui = new menu();
- gui.setTitle("Simple Menu");
- gui.setSize(800,600);
- gui.setLocation(300,200);
- gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- gui.setResizable(false);
- gui.setVisible(true);
- }
- }
- import javax.swing.*;
- import java.awt.event.*;
- import java.awt.*;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- public class menu extends JFrame implements ActionListener
- {
- private Container cn;
- private JMenuBar jmb;
- private JMenu mnuPerson, mnuSystem, mnuDisplay,mnuReport;
- private JMenuItem mnuItemAdd, mnuItemDisplayAll,mnuItemDisplayByID,mnuItemDisplayByMake,mnuItemExit;
- private JMenuItem mnuItemUpdate, mnuItemDelete,mnuItemReportAll,mnuItemReportMake;
- Absolute1 my = null;
- public menu()
- {
- cn = getContentPane();
- cn.setBackground(Color.blue);
- jmb = new JMenuBar();
- mnuPerson = new JMenu("Car!");
- mnuPerson.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemAdd = new JMenuItem("Add Car!");
- mnuItemAdd.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemAdd.addActionListener(this);
- mnuPerson.add(mnuItemAdd);
- mnuDisplay = new JMenu("Display!");
- mnuDisplay.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemDisplayAll = new JMenuItem("Display All!");
- mnuItemDisplayAll.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemDisplayAll.addActionListener(this);
- mnuDisplay.add(mnuItemDisplayAll);
- mnuItemDisplayByID = new JMenuItem("Display By Reg!");
- mnuItemDisplayByID.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemDisplayByID.addActionListener(this);
- mnuDisplay.add(mnuItemDisplayByID);
- mnuItemDisplayByMake = new JMenuItem("Display By Make!");
- mnuItemDisplayByMake.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemDisplayByMake.addActionListener(this);
- mnuDisplay.add(mnuItemDisplayByMake);
- mnuPerson.add(mnuDisplay);
- mnuItemUpdate = new JMenuItem("Update");
- mnuItemUpdate.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemUpdate.addActionListener(this);
- mnuPerson.add(mnuItemUpdate);
- mnuItemDelete = new JMenuItem("Delete");
- mnuItemDelete.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemDelete.addActionListener(this);
- mnuPerson.add(mnuItemDelete);
- mnuReport = new JMenu("Reports!");
- mnuReport.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemReportAll = new JMenuItem("Report all");
- mnuItemReportAll.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemReportAll.addActionListener(this);
- mnuReport.add(mnuItemReportAll);
- mnuItemReportMake = new JMenuItem("Make");
- mnuItemReportMake.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemReportMake.addActionListener(this);
- mnuReport.add(mnuItemReportMake);
- mnuSystem = new JMenu("System!");
- mnuSystem.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemExit = new JMenuItem("Exit!");
- mnuItemExit.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemExit.addActionListener(this);
- mnuSystem.add(mnuItemExit);
- jmb.add(mnuPerson);
- jmb.add(mnuReport);
- jmb.add(mnuSystem);
- setJMenuBar(jmb);
- }
- public void windowDeactivated(WindowEvent arg0) {
- JOptionPane.showMessageDialog(null, "Window Deactivated");
- }
- public void actionPerformed(ActionEvent e)
- {
- if(e.getActionCommand().equalsIgnoreCase("Exit!"))System.exit(0);
- if(e.getActionCommand().equalsIgnoreCase("Add car!"))
- {
- if(my == null){
- my = new Absolute1();
- my.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
- my.setVisible(true);
- my.setSize(800, 600);
- my.addWindowListener(null);
- my.setResizable(false);
- }
- if (my.isVisible())
- {
- my.setVisible(false);
- }
- my.setVisible(true);
- Absolute1 my = null;
- }
- if(e.getActionCommand().equalsIgnoreCase("Display All!"))
- {
- JOptionPane.showMessageDialog(null, "DisplayAll");
- }
- if(e.getActionCommand().equalsIgnoreCase("Report all"))
- {
- JOptionPane.showMessageDialog(null, "ReportAll");
- }
- if(e.getActionCommand().equalsIgnoreCase("Make"))
- {
- JOptionPane.showMessageDialog(null, "Make");
- }
- if(e.getActionCommand().equalsIgnoreCase("Display By make!"))
- {
- JOptionPane.showMessageDialog(null, "make");
- }
- if(e.getActionCommand().equalsIgnoreCase("Display By reg!"))
- {
- JOptionPane.showMessageDialog(null, "reg");
- }
- if(e.getActionCommand().equalsIgnoreCase("update"))
- {
- JOptionPane.showMessageDialog(null, "Update");
- }
- if(e.getActionCommand().equalsIgnoreCase("Delete"))
- {
- JOptionPane.showMessageDialog(null, "delete!");
- }
- }
- }
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.EOFException;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import java.util.*;
- public class Absolute1 extends JFrame implements ActionListener,WindowListener, MouseListener{
- private Container cn;
- private JLabel lbl;
- private JTextField txtReg, txtMake,txtModel,txtSize,txtcost;
- private JComboBox cmbMonth,cmbYear;
- private JButton btnAdd;
- RandomAccessFile rd = null;
- private String reg, make, model, size, month;
- private int year;
- private double cost;
- private JMenuBar jmb;
- private JMenu mnuSystem;
- private JMenuItem mnuItemExit;
- int[] years = {2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011};
- public Absolute1() {
- cn = getContentPane();
- cn.setLayout(null);
- cn.addMouseListener(this);
- txtReg = new JTextField("Input your Car reg!");
- txtReg.addMouseListener(this);
- txtReg.setBounds(500, 200, 200, 20);
- txtMake = new JTextField("Input your make!");
- txtMake.addMouseListener(this);
- txtMake.setBounds(500, 250, 200, 20);
- txtModel = new JTextField("Input your model!");
- txtModel.addMouseListener(this);
- txtModel.setBounds(500, 300, 200, 20);
- txtSize = new JTextField();
- cn.add(txtReg);
- cn.add(txtMake);
- cn.add(txtModel);
- cn.add(txtSize);
- JButton btnAdd = new JButton("Save!");
- btnAdd.addActionListener(this);
- btnAdd.setBounds(50, 500, 700, 25);
- cn.add(btnAdd);
- addWindowListener(this);
- jmb = new JMenuBar();
- cmbYear = new JComboBox();
- cmbYear.setBounds( 400, 25, 260, 20 );
- cn.add(cmbYear);
- for (int u = 0;u<10;u++)cmbYear.addItem(years[u]);
- mnuSystem = new JMenu("System!");
- mnuSystem.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemExit = new JMenuItem("Exit!");
- mnuItemExit.setFont(new Font("Serif", Font.BOLD, 24));
- mnuItemExit.addActionListener(this);
- mnuSystem.add(mnuItemExit);
- jmb.add(mnuSystem);
- setJMenuBar(jmb);
- }
- public void actionPerformed(ActionEvent e) {
- if(e.getActionCommand().equalsIgnoreCase("Exit!"))
- {
- this.setVisible(false);
- }
- if(e.getActionCommand().equalsIgnoreCase("Save!"))
- {
- String wat = null;
- try {
- rd = new RandomAccessFile("this","rw");
- } catch (FileNotFoundException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- }
- try {
- if(rd.length()<1)
- {
- }
- else
- {
- try {
- wat = wat + rd.readUTF();
- wat = wat + rd.readUTF();
- wat = wat + rd.readInt();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- } catch (IOException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- }
- try {
- rd.seek(rd.length());
- reg = txtReg.getText();
- reg = tools.pad(reg,10);
- rd.writeUTF(reg);
- make = "abcdefghijklmopqrstuvwxyz";
- make = tools.pad(make,20);
- rd.writeUTF(make);
- model = "qwertyuiopasdfghjklzxcvbnm";
- model = tools.pad(model,20);
- rd.writeUTF(model);
- rd.writeInt(years[cmbYear.getItemCount()]);
- rd.close();
- } catch (FileNotFoundException e1) {
- JOptionPane.showMessageDialog(null, "FUCKED");
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- public void windowClosing(WindowEvent e) {
- }
- @Override
- public void windowActivated(WindowEvent arg0) {
- }
- @Override
- public void windowDeiconified(WindowEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void windowIconified(WindowEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void windowOpened(WindowEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void windowClosed(WindowEvent e) {
- }
- @Override
- public void windowDeactivated(WindowEvent e) {
- if(rd!=null)
- {
- try {
- rd.close();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- JOptionPane.showMessageDialog(null, "FUCKYOUSHIT");
- this.setEnabled(false);
- }
- }
- }
- @Override
- public void mouseClicked(MouseEvent e1) {
- if(e1.getComponent()==txtReg)
- {
- txtReg.setText("");
- }
- if(e1.getComponent()==txtMake)
- {
- txtMake.setText("");
- }
- if(e1.getComponent()==txtModel)
- {
- txtModel.setText("");
- }
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- // TODO Auto-generated method stub
- }
- }
- public class tools {
- public static String pad(String s, int max)
- {
- if (s.length()<max)
- {
- for(int x=s.length();x<max;x++)
- {
- s = s + " ";
- }
- }
- if(s.length()>max)
- {
- s = s.substring(0, max);
- }
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement