Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,309 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 849 people online right now. Registration is fast and FREE... Join Now!




Array of Strings and cannot find symbol

 
Reply to this topicStart new topic

Array of Strings and cannot find symbol

blastdinosaur
1 Jan, 2009 - 05:38 PM
Post #1

New D.I.C Head
*

Joined: 11 Dec, 2008
Posts: 45

I am working on another of our case study this one wants us to create a program for Non-Preemptive Priority Scheduling i'm only on the preliminary part and i'm encountering something ,
CODE

/* Non-Preemptive Priority Scheduling Program
* by BlastDinosaur
*
*/
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;


public class OS extends JApplet implements ActionListener
{

JFrame hold = new JFrame();
JPanel content = new JPanel();
JLabel welcome = new JLabel("THE NPP PROGRAM!");
JLabel enter = new JLabel("ENTER JOB NAME");
JLabel priority = new JLabel("ENTER PRIORITY");
JTextField pri = new JTextField(10);
JLabel burst = new JLabel("ENTER BURST TIME");
JTextField bur = new JTextField(10);
JTextField job = new JTextField(10);
JButton button = new JButton("ENTER");
JLabel show = new JLabel();

    public void init()
    {
        
     content.setLayout(new FlowLayout());
     content.add(welcome);
     content.add(enter);
     content.add(jname);
     content.add(priority);
     content.add(plabel);
     content.add(burst);
     content.add(blabel);
     content.add(button);
     content.add(show);
     getContentPane().add(content);
     hold.setLayout(new BorderLayout());
     hold.setContentPane(content);
     hold.setSize(180,230);
     hold.setVisible(true);
     button.addActionListener(this);
     }
    
    public void actionPerformed(ActionEvent e)
{if(e.getSource() == button)
{take();}
}

public void take()
{int i;
String[] jobf;
String jobf = job.getText();
String prif = pri.getText();
int[] priarray = Integer.parseInt(prif);
String burf = bur.getText();
int[] burarray = Integer.parseInt(burf);
i++;
}
    
    
}
    
  


the problem is it says cannot find symbol on the first public class and one more how can I enter values in the public take because for example I need to do it like this,

first input
job: J1
pri: 1
bur: 2(in seconds)

then I have to put another again to another value of [i] so that I can sort them,

help please!

happy.gif



User is offlineProfile CardPM
+Quote Post


nick2price
RE: Array Of Strings And Cannot Find Symbol
1 Jan, 2009 - 05:51 PM
Post #2

D.I.C Addict
****

Joined: 23 Nov, 2007
Posts: 963



Thanked: 83 times
My Contributions
To sort out the fir problem, import
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

Second problem i have no idea what u r doing. U r using variable names declared in the method scope, and your trying to use them in the class scope. You need to make the method variables global or somthing so everything in the class can access them.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Array Of Strings And Cannot Find Symbol
1 Jan, 2009 - 06:01 PM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 6,656



Thanked: 613 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well as Nick already pointed out that your events like ActionListener and ActionEvent are defined in java.awt.event and not javax.swing.event. Those are for swing control events not basic events.

Second you are using variable names like jname, plabel, blabel etc and no where do you define those variables.

Then in your take() function you define a variable called jobf and right after it you declare jobf and set it to a value. That is redefining the variable which you can't do. Get rid of the first jobf.

Then you are using Integer.parseInt() which is going to return a SINGLE integer not an array so you can't put it into int[] variable.

These are just a few of the problems here. Hope I clarified enough. smile.gif
User is offlineProfile CardPM
+Quote Post

blastdinosaur
RE: Array Of Strings And Cannot Find Symbol
1 Jan, 2009 - 06:11 PM
Post #4

New D.I.C Head
*

Joined: 11 Dec, 2008
Posts: 45

How can I make em global?

Yes I was thinking about that and I dont know what to do,

about the cannot find symbol I understand what I missed,

anyway what Im trying to do is like filing a new job for every time they click the button,

for example the variable i is supposed to be used to be the index of that job so I can (hopefully) sort em out later,

ex input:

[1]
Job name: J1
Priority: 1
Burst Time: 3

then when I push the button again I have to put
[2]
Job name: J2
Priority: 2
Burst Time: 2

so that I can sort the value of [i] for the algorithm of the NPP Scheduling,

anyway then I should not put it into parseInt? what can I use then?
User is offlineProfile CardPM
+Quote Post

nick2price
RE: Array Of Strings And Cannot Find Symbol
1 Jan, 2009 - 06:37 PM
Post #5

D.I.C Addict
****

Joined: 23 Nov, 2007
Posts: 963



Thanked: 83 times
My Contributions
you would use parseInt to get a String to an int. The problem is that you are trying to assign a single int as an int array. What you would have to do instead is somthing like
CODE
int priarray = Integer.parseInt(prif);

which assigns the passes int to an int, not an int array. after this you can add it to an array.

The approach i would take to sort out your other problem would be to create a new class called Jobs or somthing, where you can instantiate a Jobs Object;
SO somthing like
CODE

public class Jobs{

private String job;
private String priority;
private String burstTime;

public Jobs(String job, String priority, String burstTime)
{
   this.job=job;
   this.priority=priority;
   this.burstTime=burstTime;
}
.....


This way, in your gui you can create an array of Jobs by creating an instance of the class
Jobs[] myJobs = new Jobs[3];

then provide a loop or somthing, and add the Objects to your array
CODE

for(int i = 0; i < myJobs.length; i++) //loop the array
    {
                myJobs[i] = new Jobs(//what ever the name of your input variables are); //and assign it with the data
    }


This way, you can get them into an array of your own specified type.
have fun working on this. P.s, code of the top of my head, maybe some mistakes

This post has been edited by nick2price: 1 Jan, 2009 - 06:39 PM
User is offlineProfile CardPM
+Quote Post

blastdinosaur
RE: Array Of Strings And Cannot Find Symbol
2 Jan, 2009 - 05:26 PM
Post #6

New D.I.C Head
*

Joined: 11 Dec, 2008
Posts: 45

thanks Ill try that!!!

ill post again if i finish it thanks much appreciated!

happy.gif
User is offlineProfile CardPM
+Quote Post

blastdinosaur
RE: Array Of Strings And Cannot Find Symbol
2 Jan, 2009 - 05:46 PM
Post #7

New D.I.C Head
*

Joined: 11 Dec, 2008
Posts: 45



CODE


/* Non-Preemptive Priority Scheduling Program
* by BlastDinosaur
*
*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.*;


public class OS extends JApplet implements ActionListener
{

JFrame hold = new JFrame();
JPanel content = new JPanel();
JLabel welcome = new JLabel("THE NPP PROGRAM!");
JLabel enter = new JLabel("ENTER JOB NAME");
JLabel priority = new JLabel("ENTER PRIORITY");
JTextField pri = new JTextField(10);
JLabel burst = new JLabel("ENTER BURST TIME");
JTextField bur = new JTextField(10);
JTextField job = new JTextField(10);
JButton button = new JButton("ENTER");
JLabel show = new JLabel();
JButton see = new JButton("SHOW");



    public void init()
    {
        
     content.setLayout(new FlowLayout());
     content.add(welcome);
     content.add(enter);
     content.add(job);
     content.add(priority);
     content.add(pri);
     content.add(burst);
     content.add(bur);
     content.add(button);
     content.add(see);
     content.add(show);
     getContentPane().add(content);
     hold.setLayout(new BorderLayout());
     hold.setContentPane(content);
     hold.setSize(180,230);
     hold.setVisible(true);
     button.addActionListener(this);
     }
    
    public void actionPerformed(ActionEvent e)
{if(e.getSource() == button)
{takes();}
if(e.getSource() == see)
{seeinput();}
}



public class take()
{private String jobf;
private String burf;
private String prif;

public takes(String jobf, String prif, String burf)
{this.jobf=job;
this.prif=pri;
this.burf=bur;
}
}
    
public void clear()
{job.setText("");
bur.setText("");
pri.setText("");
}

public void seeinput()
{job.setText(jobf);
bur.setText(burf);
pri.setText(prif);
}
    
}
    
  



it does '{' expected on class take,what should I do?

This post has been edited by blastdinosaur: 2 Jan, 2009 - 06:49 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 07:09PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month