473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1760
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 on XP. I think I am now at that stage of learning...
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 change at a time into his "master copy", after he...
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? What caveats should be observed in making...
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 already running, or alternatively, brings the running...
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 snippets? Are there any source safe/subversion...
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 initialize a 'const Derived1 &output'. If the...
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. In addition to background reading and...
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 work properly. The db copies outlook mailboxes......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.