javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And you think that by posting to a 4!!! year old thread that discusses the simple Hello World program will get you an answer?

This is not a thread were people can ask questions about their problem. It is a code-snippet.
Here people post code that works for tutorial purposes and to discuss what they have written.

Start a new thread

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And you think that by posting to a 4!!! year old thread that discusses the simple Hello World program will get you an answer?

This is not a thread were people can ask questions about their problem. It is a code-snippet.
Here people post code that works for tutorial purposes and to discuss what they have written.

Start a new thread

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Usually a NullPointerException means that you are trying to use something that is null. So if you get the exception at line 63:

_file.pixels[x][iy].setValue("b");

it would mean that: "_file.pixels[x][iy]" is null. So how do you populate that array?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

the implicite variable "this" is called even if it is omited:
so writing addMouseListener(this); issimilar to it's similar to this.addMouseListener(this);

I didn't understood you correctly, I thought you said this was an error

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

this instruction is ambigous: addMouseListener(this); it's similar to this.addMouseListener(this);

What do you mean by that? Do you think it is wrong?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From what I see you use a lot of "extending" that I don't think is necessary. Your code works but it could have been simpler.
First don't use the "dispose" method.

Second you need to close the the MainPage and open the PageOne.
To do that you need to call the setVisible(false) on the MainPage that is open. In order to have access to the original MainPage that you opened you need to pass it as parameter to the MapLabel.
But MapLabel is called from the MainPagePanel so that also needs to have it as parameter:

MapLabel class

MainPage mp; 

public MapLabel(Icon icon, String name, MainPage mp) {

   this.mp = mp;
}

// AT THE LISTENER:

......
PageOne po = new PageOne();
mp.setVisible(false); // disposing PageOne

// [B]mp = new MainPage();[/B] // you don't need that. It will create a new MainPage and overwrite the existing one.
// you have already created a MainPage, don't create another

But in order to call this: public MapLabel(Icon icon, String name, MainPage mp) you need:

MainPagePanel class

MainPage mp;

public MainPagePanel(MainPage mp) {
		Toolkit kit = Toolkit.getDefaultToolkit();

		image = new ImageIcon("menu1.jpg");
                this.mp = mp;
display = new MapLabel(image, "Display", mp);

And now to pass the MainPage that is opened as paramater

MainPage class

public MainPage() {
		super("Test");
		setSize(180,100);
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

// "this" is a MainPage. This MainPage that you just created and has all your Panels and labels
		mpp = new MainPagePanel([B]this[/B]);

		Container pane …
kathmartir commented: good job, your idea work well +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public static void main(String []args)
{
javaa j=new javaa(1,2,3);
j.av();
}

Actually you need to call the average() method because there is no method: [U]av[/U] declared in the class.

Also next time if you want code tags, please click the button labeled [code] ,when you create a new post

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think he wants a javax.swing.* program.

What you ask is impossible because we don't know your requirements. We cannot just start writing a program that does nothing using random commands with no purpose.

Not to mention that we don't do other's people homework on demand.
In the meantime watch how the counter of your thread reaches minus infinity :)

PS: By the way, what is that counter for and how it is different from the reputation points?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When I want to go from one frame to another I use:

JFrame.setVisible(true/false);

If you call it with false, the frame is not lost. It is just not visible. Meaning that you can call back the same method and set it to visible(true) whenever you want and the frame will reappear

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

1) Create a array, which represents a table.
2) use a for loop;

for(int i = 1; i != 5; i++)
    myArrayTable[i] = 6*i; //say, myArrayTable is already declared.

I have a question:
Why didn't you use this at the for loop:

for(int i = 1; i < 5; i++)
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
System.out.print( df.format(montantPublicite) );

"System.out.print" takes what is inside the parenthesis and displays it. If you want whatever is inside the parenthesis displayed somewhere else then take it and put wherever you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I believe that your problem is this:

String s1 = new String( secondLength );
....
lastName.getChars ( 0, 5, secondLength, 0 );

When you create the "s1" the "secondLength" array is empty. Then you call the method that gives to the array values, but the s1 was already created.
Try first to enter values to the array and then create the String "s1".

Also try to print the result at a System.out.println :

String finalResult = firstName.charAt(0) + s1 + number;
System.out.println("Final Result :"+finalResult);
Teethous commented: Very concise approach +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't you mean JTextField? If yes then you should use the 'getText' method. For a complete API:
JTextField

Also for the formatting:
SimpleDateFormat

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You think that is simple??
:-O

They are classes provided by java.

For the Date Picker, SpinnerDateModel works on its own and is very simple. Just read its API, initialize it and put it in your frame. Then use the methods described in the API to get the date value.

If you want a time picker as well you might want to extend the AbstractSpinnerModel and read its API which is at the link I gave you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For the simplest solution try:
AbstractSpinnerModel
and
SpinnerDateModel

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

- Firstly we cannot provide a system using java because this is java forum not a system forum.

- Secondly here is any program as you asked:

please please help me.. or any program..

public class Main {
  public static void main(String [] args) {
     System.out.println("Hello mhil_joy!");
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
if (appointments.getName() == null){
                newButton.setEnabled(true);
            }else {
                newButton.setEnabled(false);
            }

According the above, the button is disabled when the the getName is not null. If it always get disabled it means it is always not null. Therefor your logic must have sort of mistake when you call appointments.next(); or
you might want to check if the String is empty

if ( (appointments.getName() == null) || (appointments.getName().equals("")) ) {
                newButton.setEnabled(true);
            }else {
                newButton.setEnabled(false);
            }

Of course we don't know your logic and you should focus on getting the correct value after the next.
Add some "system.out.println" to see what values you return

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After running the code, I noticed that you declared the JTextFileds but you didn't add them to any JPanel

//Add fields to rows
		firstRow.add(nameLabel);
		secondRow.add(studentIDLabel);
		secondRow.add(transfercourseNumberLabel);
		secondRow.add(localcourseNumberLabel);

		//Add rows to panel
		fieldPanel.add(firstRow);
		fieldPanel.add(secondRow);

You add the labels but I didn't see any code the does the same for:

JTextField name = new JTextField(35);
	JTextField studentID = new JTextField(40);
		JTextField transfercourseNumber = new JTextField(40);
		JTextField localcourseNumber = new JTextField(45);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Once again:
Your code is huge, we are not your teacher to read the whole thing.
1) What errors do you get?
2) At which line?
3) What does it do, and what it is supposed to do?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks for the replies but I have already bought a new monitor and is working fine

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have been reading your thread for some time now, searched the google, asked my colleagues, called some of my old professors but still no one can answer this important question:

...Can anybody knows how can I put a table on what type of Package type (overnight and two day package) in my program..

Since I have been troubled on how I would like to display my added data to an array and if I have choose a certain package type then later if I would like to display that type of package the data being addded is being displayed in an sorted way...

What do you mean by that???? It makes no sense! Explain your program and what it does and what you want it to do

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the class:
java.text.SimpleDateFormatter

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is an example with arrays:

Empleoyee emp  = new Empleoyee(); // this is an [B]Empleoyee[/B] 

Empleoyee [] empArray  = new Empleoyee[10]; // this an array

// emp is an Empleoyee
// empArray is an array
// the empArray above is not null

//empArray[0], empArray[1], empArray[2], ... are [B]Empleoyee[/B] but they are null

empArray[0] = new Empleoyee(); // now the empArray[0] is not null

empArray[1] = emp ; // now the empArray[1] is not null

// remember empArray[0] is an Empleoyee
empArray[0].setName("aaaaaa");
System.out.println(empArray[0].getName());

int length = empArray.length; // empArray is an array
System.out.println("Number of employees: "+length);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post the whole stack trace?

java.lang.NullPointerException

It means that you are trying to use something that is null. At the stack trace you will find somewhere one of your classes mentioned. Go to that line and there something is null

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for (int l = 0; l < info.length; l++){
             info[l] = loadPlayerPositions.readLine();

             info[0] = Players.nameOfPlayer1.toString();
             info[1] = Players.nameOfPlayer2.toString();
             info[2] = Players.loadplayer1currentblock;
             info[3] = Players.loadplayer2currentblock;

             Players.loadCurrentPositions();
             Players.currentPositions();

             [B]loadPlayerPositions.close();[/B]

       }

You are inside the loop, you close the BufferedReader and when the loop runs again you try to read from a closed BufferedReader. When you close the BufferedReader you cannot read from it again. Close it after you are done reading.
Also I believe that you should check if the line read: info[l] = loadPlayerPositions.readLine(); is not null in case the file has less than 4 line

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I tried putting e.printStackTrace() but it didn't accept it saying that "void" cannot be used. When i checked, printStackTrace() was "void" after all. I tried using getMessage() and I got a message saying "Stream closed" when I tried running the program again.

catch (IOException e){
               JOptionPane.showMessageDialog(null, "IOException: " +  
               e.getMessage());
}
catch (IOException e){
    System.out.println(e.getMessage()); //returns String

               JOptionPane.showMessageDialog(null, "IOException: " +  
               e.getMessage());

   e.printStackTrace(); // is void
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have been reading this thread and didn't notice the poll. I believe the "Read Me" thread with the MVC tutorial is very nice guide to start with.
But we do need a guide with links to tutorials that will cover the aspects described in the tutorial with more detail

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Put a e.printstacktrace at the catch block, post your new code with the errors that you get

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For reading lined from a file:

try{
             BufferedReader loadPlayerPositions = new BufferedReader(new FileReader("/media/KEI-SAMA/CS11/JOKE CS11/KnowGoMilestone5/playerpositions.txt"));

String line = loadPlayerPositions.readLine();
while ([B]line!=null[/B]) {
  System.out.println("Line read: "+line);

   [B]line = loadPlayerPositions.readLine();[/B]
}
} catch (Exception e) {
  System.out.println("Exception: "+e.getMessage());
}

With that way you read each line.
Do some checking in case the file doesn't have all 4 lines that you want.
You get the exception at that line: info[0] = Players.nameOfPlayer1.toString(); probably because Players.nameOfPlayer1 is null

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

"if" and "while" both do the same thing. Check if what's inside the parenthesis is true or false.
So they will both give you the same result.
Meaning that if you had only the while it will work, because it would return true or false depending on if there will be a "next" row

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I get the problem, but I find it strange that you have it. The code should work:

ResultSet rs = ......

while (rs.next()) {
  .....
}

Is it possible that you accidentally execute the rs.next before the while loop. Also are you sure that the query actually returns: 1,2,3,4 with that order?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How many columns does the query return?
Try:

textAr.append(rs.getString(1)+"\n");
textAr.append(rs.getString(2)+"\n");
textAr.append(rs.getString(3)+"\n");

Or

ResultSet rs = stmt.executeQuery("Select col1, col2 from names");

.....

textAr.append(rs.getString("col1")+"\n");
textAr.append(rs.getString("col2")+"\n");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In order to get code, you need to give code. Then we will help you solve your problem.
Normally I would have give you pointers on how to proceed with your problem but I don't understand your problem even though this is the second time I ask you to explain it to us

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Without seeing code the only possible and logical way is when you click the button to set the variable that you display as the time back to zero

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

(((10000*5000)-2000*3000)*30/100)


/ * - * 10000 5000 * 2000 3000 30 100

Is this what you want?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
String input = in.next();
     if (input.equalsIgnoreCase("Q"))
         done = true;

when you get the input you can do:

String input = in.next();

// will return the first character
// also check the length of input (if input has length 0 you will get an error)
char inp = input.charAt(0);
// check if inp is a character

If you check the API for class: Character it has a lot of "is..." methods that will help you check what you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the class javax.swing.ImageIcon with constructor: ImageIcon(String filename) Then you can use a JLabel with constructor: JLabel(Icon image) You might want to consult the above classes' API

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't write this:

return (((multi * seed) + incr) % modu);

When you calculate the result store it into a variable. Then change the value of the seed with that variable and then return it.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well the code runs as it's supposed to be.
The code is not very complicated to provide any suggestions on how to do things differently

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And where are you having problem? Don't expect to do this for you and if reply by saying that you want some guidelines then I will ask guidelines at which part of your problem:

1) Creating the database
2) Open Database Connection (JDBC Connectivity)
3) Write the query (SQL query Knoledge)
4) Get the data from the database by running the query through java (package java.sql.*)
5) Create the JForm, JPanel, JTable (package jacax.swing.*)
6) Putting the data into the JTable (package jacax.swing.*)

I suggest to put the above steps in different classes

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As JamesCherrill said, we will not read your code the way you posted it. Use code tags. When you create a new post click the code button and put your code between the tags

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
<select name="selectedUniversity" >
  <option>Brunel</option>
  <option>Kingston</option>
  <option>Kent</option>
</select>

Submit the form to the next page and at the next page have this code:

<%
String university = request.getParameter("selectedUniversity");
if (university==null) university = "";
%>


<div id="Layer1" style="position:absolute; left:368px; top:175px; width:257px; height:100px; z-index:1">
Your University: 
<input type="text" name="favorite" value="<%= university%>" size="20">
</div>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I never had to do something like this before, so frankly I am not in the mood to write code that does that.
But If I were to do this I would look at this site:
http://www.w3schools.com/default.asp
for tutorials on the subjects:
HTML DOM and
DHTML

You can use the id attribute to get the "select" and "option" tags as javascript variables and by using the above tutorials and API you can manipulate them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If it doesn't work then there is a problem with the "moveOptions" method for which you didn't provide code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Please forgive but I don't understand what you mean by new layer. Can you post code or a picture indicating where you want the "uni" to be displayed?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all this is a question for the JSP forum.
Secondly what do you mean when you say "heading". Explain better with some code.
Also you can submit the page and when you go at the the next page you can do this:

<%
String uni = request.getParameter("uni");
%>
<head>
<title><%= uni%><title>
</head>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And a new suggestion if you can't get you code to work.
I find your solution very confusing and not object oriented. I believe that you problem is that when it comes to time you return values from the array, but when it comes to name you declare an array but you use a single String variable which you set and return. Therefor all the times will have the same name from the method "getName".
Shouldn't you have a method that depending on the time or its position you set the at the appropriate position the name at the StringArray?

I don't know your whole logic but you can try this:

// SINGLE CLASS WITH JUST PROPERTIES

public class Appointment {
  private int time = 0;
  private String name = "";

  public Appointment() {
 
  }

// add get,set methods

}

Then have a class like this:

public class AppointmentBook {
  private int position = 0;
  private int max = 0;
  private Appointment [] appointments = null;

  public Appointment(int max) {
     // this.max is the global
    // max is the local from the argument
     this.max = max;

    //appointments is the global
    appointments = new Appointment[max];
  }
  
   // create methods that add and get appointments to the array by increasing the position variable
  // also check the value of position in case you have too much appointment
  // add whatever functionality you want
}

examle:

Appointment ap = new Appointment();
ap.setName("Name");
ap.setTime(200);

Appointment [] appointS = …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all look at this again:

public void setName(String appt){
        temptext = appt;
    }
    public String getName(){
        return appt;
    }

You return the appt variable but in the code that variable never takes value. You just declare it and it always returns null. But you set the value to the temptext variable; shouldn't you return that instead?
Also these 2 appt variables are NOT the same:

private Strign appt = null;

    public void setName(String appt){ // appt exists only inside this method
// it overrides the global
       temptext = appt;
    }

When you call the set-method the global variable appt doesn't take value.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post more code. Skip the presentation code and post for start just the code with the logic.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you see something wrong with this code:

public void setName(String appt){
        [B]setName[/B](appt);
    }

You calling the same method. When you call setName it will call setName which is inside it, which will call setName which is inside it, which will call setName which is inside it, . . . .

You need to assign the property name inside the method:

public void setName(String appt){
        name = appt;
    }
JimD C++ Newb commented: Thank you! +1