472,325 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 software developers and data experts.

making a set of code copy and pasteable to someone elses editor

ok the following code , is the code for my program, basicly, i use bluej, so i can just copy and paste some code into the forums and someone else can copy it in to their editor, so basicly i want someone to show me how to make this set of code to be able to run itself, i have marked the main areas of the code like the main and graphics panel etc sorry about the load of code, but this is important to me that i get this all working together. thanks guys



Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.util.Calendar;
  5. import java.text.SimpleDateFormat;
  6. import java.lang.Object;
  7. import java.io.*;
  8. import javax.swing.event.*;
  9. import javax.swing.JCheckBox;
  10. public static void main(String[] args)    ]// main statement, i want it to goto 
  11.    {
  12.       main m = new main();
  13.    }
  14. public class main implements ActionListener   //this
  15. {
  16.         JFrame f1,f2;
  17.         JPanel p1,p2,p3,p4;
  18.         String id,enterstring,name,namestring,idstring,str;
  19.         GP g1;
  20.         JRadioButton bathroom,office,nurse,other;
  21.         JButton submit,returnbutton;
  22.         JTextField idnumber;
  23.         JLabel idprompt,what,time,namelabel;
  24.         boolean show,bathroomb,officeb,nurseb,otherb;
  25.         int idnum,counter;
  26.         SimpleDateFormat sdf;
  27.        String[] namearray; 
  28.        int[] idarray;
  29.        int a,b,idint,enter,teacher;
  30.      public main()
  31.     {   
  32.         teacher = 1234567890;
  33.          bathroomb = false;
  34.          officeb = false;
  35.          nurseb = false;
  36.          otherb = false;
  37.         namearray = new String[3];
  38.         idarray = new int[3];
  39.      sdf = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z");  
  40.        show=true;
  41.         a=0;
  42.         b=0;
  43.         namelabel = new JLabel("");
  44.        bathroom = new JRadioButton("Bathroom");
  45.         bathroom.setMnemonic(KeyEvent.VK_C);
  46.         bathroom.setSelected(false);
  47.         bathroom.addActionListener(this);
  48.         counter = 1;
  49.        office = new JRadioButton("Office");
  50.        office.setMnemonic(KeyEvent.VK_C);
  51.         office.setSelected(false);
  52.          office.addActionListener(this);
  53.        nurse = new JRadioButton("Nurse");
  54.         nurse.setMnemonic(KeyEvent.VK_C);
  55.         nurse.setSelected(false);
  56.          nurse.addActionListener(this);
  57.        other = new JRadioButton("Other");
  58.         other.setMnemonic(KeyEvent.VK_C);
  59.         other.setSelected(false);
  60.          other.addActionListener(this);
  61.         idprompt = new JLabel("Enter ID Number");
  62.         idnumber = new JTextField(14);
  63.         f1 = new JFrame("Hall Pass");
  64.           f1.setSize(550,200);        
  65.         Container c1 = f1.getContentPane();
  66.         time = new JLabel("left at "+sdf.format(new java.util.Date(System.currentTimeMillis())));
  67.         id = "123";
  68.         p1 = new JPanel();
  69.         p1.setSize(500,150);
  70.         p1.setLayout(new BorderLayout());
  71.  
  72.           what = new JLabel("");
  73.  
  74.        bathroom.addItemListener(new Item());
  75.        other.addItemListener(new Item());
  76.         nurse.addItemListener(new Item());
  77.         office.addItemListener(new Item());
  78.         returnbutton = new JButton("Return");
  79.         returnbutton.addActionListener(this);
  80.         submit = new JButton("Submit");
  81.         submit.addActionListener(this);
  82.  
  83.         p2 = new JPanel();  //panel to add JLabel and TextField
  84.  
  85.         g1 = new GP();    // runs the graphics panel down there
  86.          p1.add(g1,BorderLayout.CENTER);
  87.  
  88.                   //g1.setBackground(new RGB(255, 255, 255));
  89.        g1.add(idprompt);
  90.        g1.add(idnumber);
  91.         p2.add(submit);
  92.         g1.add(what);
  93.  
  94.         p1.add(p2,BorderLayout.SOUTH);      //adds p2 to south (Bottom) Graphics Panel will be added to Center    
  95.         c1.add(p1);
  96.  
  97.  
  98.         f1.show();
  99.  
  100.  
  101.     }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.     public class Item implements ItemListener{
  109.  
  110.        public void itemStateChanged(ItemEvent evt) {
  111.  
  112.             if (evt.getStateChange() == ItemEvent.SELECTED) {
  113.  
  114.  
  115.              if (bathroom.isSelected()){
  116.  
  117.                  bathroomb = true;
  118.                  System.out.println(bathroomb);
  119.                 }
  120.              if (office.isSelected()){
  121.  
  122.                  officeb = true;
  123.                 }    
  124.              if (nurse.isSelected()){
  125.  
  126.  
  127.                  nurseb = true;
  128.                 }  
  129.              if (other.isSelected()){   
  130.                  otherb = true;
  131.  
  132.                 }
  133.         }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.         }
  140.     }
  141.  
  142.       public void actionPerformed (ActionEvent event)
  143.       {
  144.   try {
  145.         BufferedReader in = new BufferedReader(new FileReader("names.txt"));
  146.  
  147.         if (event.getSource() == returnbutton)
  148.         {
  149.             f1.show();
  150.  
  151.  
  152.         }
  153.  
  154.        //idnum = Integer.Parseint(enter);
  155.  
  156.  
  157.         if (event.getSource() == submit)
  158.         {
  159.  
  160.        for(int i=0; i<6; i++){
  161.     str = in.readLine().trim() ;
  162.        if(i<3){
  163.           namearray[a] = str;
  164.           a++;
  165.         }else{
  166.             idarray[b] = Integer.parseInt(str);
  167.             b++;
  168.          }
  169. }
  170.  
  171.  
  172.  
  173.         in.close();
  174.  
  175.  
  176.  
  177.            enterstring = idnumber.getText();
  178.            enter = Integer.parseInt(enterstring);
  179.            for(int b = 0;  b< 3; b++)
  180.            {
  181.                //number 1
  182.            if (enter==idarray[0])
  183.            {
  184.                  g1.remove(idnumber);
  185.                  p1.remove(submit);
  186.                  g1.remove(what);
  187.                  g1.remove(idprompt);
  188.                   p2.remove(submit);
  189.                   namelabel.setText(namearray[0]);
  190.                   g1.add(namelabel);
  191.                  g1.add(bathroom);
  192.                  g1.add(office);
  193.                  g1.add(nurse);
  194.                  g1.add(other);
  195.                                       f1.dispose();
  196.                       f1.show(); 
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.                //  nurse.addItemListener(new ItemListener() {
  205.  
  206.                     if (bathroomb == true){
  207.                         g1.remove(namelabel);     
  208.                  g1.remove(namelabel);
  209.                  g1.remove(bathroom);
  210.                  g1.remove(office);
  211.                  g1.remove(nurse);
  212.                  g1.remove(other);
  213.                       g1.setBackground(Color.red);
  214.                       p2.add(returnbutton);
  215.                       namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
  216.                        g1.add(namelabel);
  217.                        g1.add(time);
  218.                      f1.dispose();
  219.                       f1.show();
  220.                     }
  221.                     else             
  222.  
  223.  
  224.  
  225.  
  226.  
  227.                   if (officeb == true){
  228.                        g1.remove(namelabel);     
  229.                  g1.remove(namelabel);
  230.                  g1.remove(bathroom);
  231.                  g1.remove(office);
  232.                  g1.remove(nurse);
  233.                  g1.remove(other);
  234.                       g1.setBackground(Color.red);
  235.  
  236.                       p2.add(returnbutton);
  237.                       namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
  238.                        g1.add(namelabel);
  239.                        g1.add(time);
  240.                       f1.dispose();
  241.                       f1.show();
  242.  
  243.                     }
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.                   if (nurseb == true){
  254.  
  255.                        g1.setBackground(Color.red);
  256.  
  257.                       p2.add(returnbutton);
  258.                       namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
  259.                        g1.add(namelabel);
  260.                        g1.add(time);
  261.  
  262.  
  263.  
  264.                     }
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.                   if (otherb == true){
  272.  
  273.                        g1.setBackground(Color.red);
  274.  
  275.                       p2.add(returnbutton);
  276.                       namelabel.setText(namearray[0]+" is currently using the pass the time left was ");
  277.                        g1.add(namelabel);
  278.                        g1.add(time);
  279.  
  280.  
  281.                     }
  282.  
  283.  
  284.                 }
  285.                  else{
  286.              what.setText("Incorrect Login");
  287.             }
  288.  
  289.  
  290.  
  291.  
  292.               //g1.setBackground(Color.red);
  293.  
  294.              // p2.add(returnbutton);
  295.  
  296.              // g1.add(time);
  297.               f1.dispose();
  298.               f1.show();
  299.             }
  300.  
  301.  
  302.         //number 2
  303.         if (enter==teacher)
  304.         {
  305.             f1.dispose();
  306.         }
  307.           if (enter == idarray[1])
  308.            {
  309.                  g1.remove(idnumber);
  310.                  p1.remove(submit);
  311.                  g1.remove(what);
  312.                  g1.remove(idprompt);
  313.               g1.setBackground(Color.red);
  314.               p2.remove(submit);
  315.               p2.add(returnbutton);
  316.                namelabel.setText(namearray[1]);
  317.              g1.add(namelabel);
  318.               g1.add(time);
  319.               f1.dispose();
  320.               f1.show();
  321.             }
  322.  
  323.             else{
  324.              what.setText("Incorrect Login");
  325.             }
  326.         }
  327.           if (enter == idarray[2])
  328.            {
  329.                  g1.remove(idnumber);
  330.                  p1.remove(submit);
  331.                  g1.remove(what);
  332.                  g1.remove(idprompt);
  333.               g1.setBackground(Color.red);
  334.               p2.remove(submit);
  335.               p2.add(returnbutton);
  336.                namelabel.setText(namearray[2]);
  337.              g1.add(namelabel);
  338.               g1.add(time);
  339.               f1.dispose();
  340.               f1.show();
  341.             }
  342.  
  343.             else{
  344.              what.setText("Incorrect Login");
  345.             }
  346.  
  347.  
  348.             idnumber.setText(null);
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.           g1.repaint();
  357.  } catch (IOException e) {
  358.     }
  359.         }
  360.     }
  361.  
  362.  
  363.  
  364.  
  365. public class GP extends JPanel  //graphics panel
  366.  
  367. {
  368.  
  369.  
  370.     public GP()
  371.      {      
  372.  
  373.  
  374.  
  375.  
  376.         setBackground(Color.green);
  377.  
  378.      }
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.     public void paint(Graphics g)
  386.     {
  387.      super.paint(g);
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.     }
  395.  
  396. }
Nov 1 '07 #1
13 1632
r035198x
13,262 8TB
So, where did you get this code from?
I haven't put it into any of my editors but what happens when you put that main method inside that main class and try to compile and run it?
Nov 1 '07 #2
i wrote this code in bluej ( a beginer program)

Expand|Select|Wrap|Line Numbers
  1. public class main implements ActionListener
  2. {
error: class main is public , should be declared in a file named main.java
Nov 1 '07 #3
basically, i need help with this program, but too fully understand the problem, the people who want to help me, actually will have to put this code into their own editor and compile it themselves to see whats actually wrong with it.

thanks.
Nov 1 '07 #4
r035198x
13,262 8TB
i wrote this code in bluej ( a beginer program)

Expand|Select|Wrap|Line Numbers
  1. public class main implements ActionListener
  2. {
error: class main is public , should be declared in a file named main.java
In Java you can have only one public class in a source file. Either have each of your classes in separate files or remove the public modifier from all of then (you can leave the one whose name matches name of the source file if you want).
Nov 1 '07 #5
I still dont understand what you mean
Nov 1 '07 #6
I want to do the second option
Nov 1 '07 #7
r035198x
13,262 8TB
I still dont understand what you mean
I thought you said that you wrote this program. So you should understand what I mean by a public class because you wrote the code with the public classes.
I have already explained what the second option entails. Removing the public access modifier from the headers of your classes.
Nov 1 '07 #8
ugh..................................
Nov 1 '07 #9
r035198x
13,262 8TB
ugh..................................
What now?
Perhaps if you explain the part of my reply that you didn't understand ...
Nov 1 '07 #10
what should i put instead of "public class"

and i know i should know this, but i dont.
Nov 1 '07 #11
r035198x
13,262 8TB
what should i put instead of "public class"

and i know i should know this, but i dont.
In "public class", public is the access modifier. So when I say remove the public class modifier, I mean change "public class" to just "class".

P.S Are we later on going to get to a point when you say that you are actually not the one who wrote this code?
Nov 1 '07 #12
I did write this code, in bluej, but i have yet to learn how to like make it all one giant code together. its a hall pass program for a class that i have
Nov 1 '07 #13
thanks bro. now on to the real problem, check out my new thread ;)
Nov 1 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running...
1
by: enrio | last post by:
I have made a number of changes to the code of an access 2000 application, and now the person responsible for the application wants to import one...
192
by: Vortex Soft | last post by:
http://www.junglecreatures.com/ Try it and tell me what's happenning in the Microsoft Corporation. Notes: VB, C# are CLS compliant
90
by: Ben Finney | last post by:
Howdy all, How can a (user-defined) class ensure that its instances are immutable, like an int or a tuple, without inheriting from those types?...
5
by: Daniel | last post by:
Hey guys What is the best way in c# to ensure that once your app is running, if the user then clicks to run it again it notifies them it is...
13
by: frk.won | last post by:
I am interested in learning how to use the VS 2005 code snippets. However, I wish to know what are the best ways to source control the code...
10
by: JurgenvonOerthel | last post by:
Consider the classes Base, Derived1 and Derived2. Both Derived1 and Derived2 derive publicly from Base. Given a 'const Base &input' I want to...
25
by: doznot | last post by:
Let's say you want to use Moodle to teach an introductory class in PHP programming. Some of the students have little or no computer experience. ...
0
by: sourpo | last post by:
wonder if anyone can help... I have access db with a whole lot of vb code... If i use access 2000 it works perfectly but when using 2003 it doesn't...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.