javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also you are making the same mistake you did in your initial post.
Remember, in order to print the text value of the node you are using this method:

System.out.println(node.getNodeName() + ":" + node.[B]getTextContent()[/B]);

So why are using this: node.setNodeValue("") in order to change its value?

Use the equivalent setTextContent("") method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also a good way to find out what type of node you have is this:

public static void main(String[] args) {
        System.out.println("ATTRIBUTE_NODE             :"+Node.ATTRIBUTE_NODE);
        System.out.println("CDATA_SECTION_NODE         :"+Node.CDATA_SECTION_NODE);
        System.out.println("COMMENT_NODE               :"+Node.COMMENT_NODE);
        System.out.println("DOCUMENT_FRAGMENT_NODE     :"+Node.DOCUMENT_FRAGMENT_NODE);
        System.out.println("DOCUMENT_NODE              :"+Node.DOCUMENT_NODE);
        System.out.println("DOCUMENT_TYPE_NODE         :"+Node.DOCUMENT_TYPE_NODE);
        System.out.println("ELEMENT_NODE               :"+Node.ELEMENT_NODE);
        System.out.println("ENTITY_NODE                :"+Node.ENTITY_NODE);
        System.out.println("ENTITY_REFERENCE_NODE      :"+Node.ENTITY_REFERENCE_NODE);
        System.out.println("NOTATION_NODE              :"+Node.NOTATION_NODE);
        System.out.println("PROCESSING_INSTRUCTION_NODE:"+Node.PROCESSING_INSTRUCTION_NODE);
        System.out.println("TEXT_NODE                  :"+Node.TEXT_NODE);
        /*
        System.out.println("DOCUMENT_POSITION_CONTAINED_BY:"+Node.DOCUMENT_POSITION_CONTAINED_BY);
        System.out.println("DOCUMENT_POSITION_CONTAINS:"+Node.DOCUMENT_POSITION_CONTAINS);
        System.out.println("DOCUMENT_POSITION_DISCONNECTED:"+Node.DOCUMENT_POSITION_DISCONNECTED);
        System.out.println("DOCUMENT_POSITION_FOLLOWING:"+Node.DOCUMENT_POSITION_FOLLOWING);
        System.out.println("DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC:"+Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);
        System.out.println("DOCUMENT_POSITION_PRECEDING:"+Node.DOCUMENT_POSITION_PRECEDING);
        */
    }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You cannot execute java code from inside javascript.

You need to submit the data and then update the textfields:

String mobile = request.getParameter("mobile");
String username="";
String password="";
String message=null;

if (mobile !=null) { // the first time the page will render you will not have the mobile, so skip this part

  // use the mobile to get the data
  // depending on the results generate the appropriate html code
  // If there is any kind of error store it into the String message:

  try {
     if mobile OK   {
       message = "Data retrieved successfully";
       username = ....;
       password = ....;
     }
     else message="Could not get data";
  } catch (Exception e) {
    message = "An error has occured";
  }

}


// the rest of the HTML with the javascript validation code:

<%
if (message!=null) {
%>
Results: <%= message%>
<%
}
%>
<form name="mobileForm" action="" method="post">
   <input type="text" name="mobile" value="<%= mobile%>">
   <input type="text" name="username" value="<%= username%>">
   <input type="text" name="password" value="<%= password%>">
</form>

The above is simple, beginners way, but not very efficient.
For what you are trying to accomplish:

the values of other attributes like username and password should be automatically retrieved

you will need to learn Ajax.
But given the code you just wrote, you need to learn first proper jsp, understand that javascript is not java and cannot be mixed in the way you did, understand how java code inside the jsp is executed and how it renders the page, what happens when the page loads …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to add get, set methods in your class in order to have access to the private variables:

public int getRank() {
   return rank;
}
public void setRank(int rank) {
   this.rank = rank;
}

The same for the title.


Do you know how to sort an array of integers. If yes then it is the same thing. You will have to use the rank variable though to do the comparison:

for (int i=0;i<movie.length;i++) {
  for (int j=i;j<movie.length;j++) {
     // use the movie[i].getRank(), movie[j].getRank() to compare and sort.
   if (movie[i].getRank() > movie[j].getRank()) {

  } else (movie[i].getRank() == movie[j].getRank()) {
      // If they are equal use the title as well
      if  ( movie[i].getTitle().compareTo(movie[j].getTitle()) > 0 ) {
         // the compareTo method is used to compare Strings
      }
  }

  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Scanner br = new Scanner(System.in);
int num = br.nextInt();
Integer a = Integer.valueOf(num);
System.out.println(a.toBinaryString(num));
System.out.println(a.toOctalString(num));
System.out.println(a.toHexString(num));

The toBinaryString and the other methods are static, so you don't need to create a new Integer object. What's the point of using the object created if you are going to pass as parameter the number used to create it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Lots of errors showing.. When compiling....

WOW !

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I can write this code but I can't Complete it

As masijade said post what you have done so far and we will see what we can do for you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

first of all what the javascript methods that you have at the onclick do, and second why don't you submit without the onclick() ? Since it is type="submit" once the button is clicked the form will be submitted anyway.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because you add it only to vector and not the JList:

gf.vf.add(file);

You added it successfully to the Vector but where is the code that adds it to list?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This is what is displayed:

<option>[B]MCA[/B]</option>

This is what it is sent with the request:

<option value="[B]MCA[/B]">MCA</option>

Meaning that there will be cases that what you display is different from what you want to sent:
Example:

<select [B]name[/B]="product">
<option [B]value[/B]="000-001">Product Name 1</option>
<option [B]value[/B]="000-002">Product Name 2</option>
</select>

Remember that you send the value attribute at the request and you get it using the name. Like you did: request.getParameter("product") will return one of those: 000-001, 000-002. Not what is displayed between the "option" tags

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

user can go the browser and type the url he wants

Then after the user logs in put in the session the username and the user role (ADMIN or USER)

Then at every page get the info from the session and if someone has gone to an ADMIN page when in the session the role saved is USER then use javascript to go back and display message.

Even in the more secure sites, any one can just type the url. But if they are not logged in they are reditrected.

Also at logout remove those values from the session.

After login:

// 'username' variable the one the user entered and 'role' the one // taken from the database. If login successful put those values:
session.setAttribute("USERNAME",username);
session.setAttribute("ROLE",role);
// and redirect to the next page.

At the begining of every page

String username = (String)session.getAttribute("USERNAME");
String role = (String)session.getAttribute("ROLE");

// if the above values are null, means that the user has not login.
// if this page is to be accessed only by an ADMIN the redirect

// After logout

session.setAttribute("USERNAME",null);
session.setAttribute("ROLE",null);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No, args[0] is not null. The array args has length 0. So the args[0] gives you the exception since there is no '0' element; the length of the array is 0.
The elements of the args will never be null .
Depending on the number of parameters you pass the array args will be created with those parameters. So if you pass 2 parameters, the args will have length 2. args[0], args[1] will have those values.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After taking a closer look at the code you don't need the casting. Since you read from the file a Music object, it doesn't matter what type of music it is:

while (true) {
     Music music = (Music)inFile.readObject();
     musicArray[count] = music;
     System.out.println(count+": "+musicArray[count]);
     count++;
}

Also I would suggest to put the EOFException inside the while loop.

while (true) {
     try {

     } catch (EOFException eofe) {
         break;
     }
}

Leave the rest of the exceptions outside. With that way you will exit the loop once you are done reading the file and then you can do whatever you want with the array, without having to end the program.
Then after the while loop through the array and print its elements

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Even though from your code you have figured out on your own how to use array of objects here is a small example:

Music [] array = new Music[3]; // array is an array and it is not null

// Its elements are so you need to initalize them
array[0] = new RockSong();
array[1] = new ClassicalPiece();
array[2] = new Musical();
// array[0], array[1], array[2] are Music

for (int i=0;i<array.length;i++) {
   if  (array[i] instanceof RockSong){
        RockSong rs = (RockSong)array[i]; // this is how you cast
  } else ...
}

Now as far as the rest of your code:

This is an endless loop because you don't specify when to stop, nor you know the end of the file or how many Music objects are in the file.

while (true)
{
    Music music = (Music)inFile.readObject();

I don't know what will the method do if there are no more objects. Maybe that is why you are getting a NullPointerException. Try to print what you get as soon you read the file and try it with a small file that has only 2 objects

Second, What is the format of the file. I mean how were the objects serialized?


Also here a suggestion depending on your requirements.
Another way for the file to have more than one Music objects then why don't you serialize a Vector:

Vector<Music> v = new Vector<Music>();

v.add(new RockSong());
v.add(new ClassicalPiece());
v.add(new Musical());

// serialize the Vector in the file.
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So i cant say this in the main method? .....
isItPrimeorNot = isPrime(num);

Sorry im new to Java. (:

You can make the method static. Like the main.

GTJava commented: Very helpful! +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After searching for examples on the net, I found this:
Assuming your file is like this:

XXXX
aaaaa
bbbbb

And you run this:

RandomAccessFile raf = new RandomAccessFile("fileName","rw");
            
            FileChannel fc = raf.getChannel();
            fc.position(0);
            fc.write(ByteBuffer.wrap("1234".getBytes()));
            
            fc.close();
            raf.close();

You will get this:

1234
aaaaa
bbbbb

But if you write this: fc.write(ByteBuffer.wrap("1234567".getBytes())); You will get this:

1234567aaa
bbbbb

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think that the RandomAccessFile might help you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would have used the sleep method:

// line read:
line = readLine();

// take the time at the end of the line:
lone time = ... ;

try {
  Thread.sleep(time);
} catch (Exception e) {
}

// repeat the loop

I would suggest to put the above in a Thread class and start it. When the "stop" button is clicked, you can call the sleep method on the above thread.
Actually I don't know if you can do that, but if you check the API you will find a method that will cause your thread to wait. Maybe the 'wait' method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because you only have ONE tempPerson object. You have the same instance of it:

tempPerson.setPerson(tempName, tempAddress, tempBirthDate);

System.out.println(tempPerson.getLastName()); // <-- OK here

student.add(new Student(tempPerson, tempCompDate, gpa, credits));

System.out.println(student.get(counter).getPerson().getLastName());

The last system.out at the above code prints the name correctly because it is the last one read from the loop. Then when you loop again you replace the name in the tempPerson object, and you put the latest in the list. Then you print what you read and you see correct results.
But
You put in the Student object the tempPerson. So when you do this: tempPerson.setPerson(tempName, tempAddress, tempBirthDate); you change the value of tempPerson.
Since in java all the objects are passed by reference ALL the student objects you created have the SAME tempPerson instance.
So when you change the tempPerson, it changes that tempPerson in all the Students that are in the ArrayList.

Inside the loop you create a new Student each time before you put it in the list: student.add(new Student(tempPerson, tempCompDate, gpa, credits)); Do the same for the rest:

tempName = new ....();
tempAddress = new ....();
tempBirthDate = new ....();
tempPerson = new ....();
tempCompDate = new ...();

tempName.setName(firstName, middleInitial, lastName, suffix);
tempAddress.setAddress(addLine1, addLine2, city, state, zip);
tempBirthDate.setDate(BirthDayDateInt, BirthDayMontInt, BirthDayYearInt);
tempPerson.setPerson(tempName, tempAddress, tempBirthDate);
tempCompDate.setDate(CompletionDayInt, CompletionMonthInt, CompletionYearInt);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It will work, but don't forget that each element of the iterator will have one of these:
java.util.Map.Entry

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try run it without the .class extension:
> java Hi

Then post the error that you will get :)

darkagn commented: snap +3
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to use java.util.Date, not java.sql.Date.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You aren't making any sense

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is like I said. You lack the very basics and you should be ready to accept criticism:

Java is executed at the server. Then the page is generated and then send to the client pure html.

Meaning that this:

onChange='[B]<%session.setAttribute("currentTable", request.getParameter("tableSelect"));%>[/B]; testForm.submit();'

is not executed then you change the drop down list.

Java and javascript ARE NOT THE SAME

Jave is executed at the server, the javascript at the client and it has absolutely NO access to java classes or objects.

When you submitted, you send to the server the request, then this is executed: session.setAttribute("currentTable", request.getParameter("tableSelect")); Then you receive at the client this:

<select name='tableSelect' onChange='testForm.submit();' style="text-align:center">

Only the 'testForm.submit();' will be executed at the onchange because it is javascript not java. The java part has already been executed when you submitted.

This works:

document.formName.inputName.value = '<%= (String)session.getAttribute("..")%>'

because first the java scriplet is evaluated and then sent to the client. What you actually see to your browser is this.

document.formName.inputName.value = 'theValueReturned';

No matter what you do, you cannot change a java variable if you don't submit.
So if you look only at your java code:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Test Page</title>
    </head>
    <body>
        <%
            [B]String choice = (String) session.getAttribute("currentTable");[/B]
        %>
        <form method="post" name="testForm" action="Test.jsp">
            <select name='tableSelect' onChange='<%[B]session.setAttribute("currentTable", request.getParameter("tableSelect"));[/B]%>; testForm.submit();' style="text-align:center">
                <option value='--Select Table--' <%= ("--Select Table--".equals(choice)) ? ("selected='selected'") : ""%> >--Select Table--</option>
                <option value='CONFIG_SOURCE' <%= ("CONFIG_SOURCE".equals(choice)) ? ("selected='selected'") : ""%> >CONFIG_SOURCE</option>
                <option value='CONFIG_PROCESS' <%= ("CONFIG_PROCESS".equals(choice)) ? ("selected='selected'") …
peter_budo commented: Very truth, nice code provided +11
kvprajapati commented: Great explanation. +6
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is how:
1) Post to correct forum
2) Be more descriptive on your problem
3) Show some effort

If you are talking about a web application

4) Learn about request, session
5) Learn about cookies
6) Learn about MVC (find the tutorial at the jsp forum)

Do you have a working web application were the user can login and view the items?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At the validation I believe that the seconds should until 59. For the hours you 23, 59. Why not the same for seconds.

For the extract when you multiply and then do a mod, you will get 0.

123 * 100 = 12300
12300 mod 100 = 0
12300/100 = 123

mod returns what is left from the division:
9 = 2 * 4 + 1
9 mod 2 = 1
9 mod 4 = 1

This is the time: 125345 (12:53:45)
In java when you divide an int with an int you will get an int:

125345/100 = 1253
1253 * 100 = 125300

125345/100.0 = 1253.45

So when you divide by 100 you have:
1253
The time is:
125345
1253
Think how can you get the seconds.

THEN:
1253 / 100 =
12
Now how can you get the minutes.

The 12 is the hours

tom.t commented: Very helpful. Thank you. +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hi :)
for the first problem you could do something like this:

public class Mymath {

    public calculateFactor( int a, int b ) {
        if ( a < b && b % a == 0 )
            return true;
        elif ( a > b && a % b == 0 )
            return true;
        else
            return false;
    }
}

and for the second part see if this is any helpful :):

import java.util.Scanner;

public class Test {

	public static void main( String[] args ) {
	    Scanner in = new Scanner( System.in );
	    String goOn = "y";
	    int n, largest = 0;
	    do {
	        System.out.println( "Input an integer number:" );
	        n = in.nextInt();
	        
	        for ( int i = 1; i < n; i++ )
	            if ( n % i == 0 )
	                if ( i > largest )
	                    largest = i;
	        System.out.println( "Largest divisor: " + largest );
	        System.out.println( "Another input (y/n)?" );
	        goOn = in.nextLine();
	        goOn = in.nextLine(); //doesn't work in there's only one don't know why.
	        largest = 0;
	        
	    } while ( goOn.equals( "y" ) );
      }
}

Your first code will not compile and it is not java (elif)

The second is totally inefficient and shows no thinking at all to the real problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why don't you use the post method?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

------------------------------------------------------------------------------------------------MY CODE-------------------------------------------------------------------------------------------------------------------------------------------------------


<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
<head><title>JSP Page</title></head>
<body>

<%
String school = request.getParameter("name");
String name = request.getParameter("username");
String email = request.getParameter("txtEmail");
String pass1 = request.getParameter("pass1");
String pass2 = request.getParameter("pass2");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:shobana", "SYSTEM", "nagalakshmi");

Statement st = con.createStatement();

String sql = ("INSERT INTO register VALUES ('" + school+ "','" + name + "','" + email + "','"+ pass1 +"','"+ pass2+"') ");
st.executeUpdate(sql);
con.close();

%>
connection succssful
</body>
</html>

And what is the point of this post? This is a 4 year old thread which has been revived 1 year ago, with no useful information. Can someone please close this?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually I understood that the objective was to monitor how many times a word appeared.
I would suggest sth like this:

String word;
Vector linesAppeared;

And the size of the vector would be how many times the word appeared.

You must notice that from the code given, the words that the OP wants to search for are predetermined. And originally he was searching for the frequency of their appearance.
The reason I didn't want to go into the OO solution was the novice level of the poster, and I wanted to stick to the solution that he thought.


Thanks for your congrats remark
Of course if

BestJewSinceJC commented: actually agreed - the extra class may be more confusing than anything +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I'm having Java course and I have to submit the following programs by the coming Wednesday

Was the assignment given to you today? If no, then what were you doing all this time? If yes, then you have a very demanding teacher.

Please may you code those for me for this time?

Does this mean that next time you will do it on your own?
But if you can't do this now, how will you be able to do the more advanced? Not to mention that you would not have learned how to think on your own, so even if you do understand the code that we would have given you, you would not be able to think the solution for the next assignment.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I'm not crazy about this anonymous up/down stuff. I'm a big believer that if you criticize or praise someone in a public way, you should attach your name to it so everyone knows who did it.

Well as VernonDozier said, shouldn't you at least be able to mention the reasons why you Up or Down voted a post, or be able to see who did it to your post?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

So from what I understood:
The reputation system affects both the rep points as well as the voting points of the specific post,
but
The voting system affects only the voting points?

Also is it possible when the user clicks the Up,Down button to display a pop up confirmation dialog? Once I wanted to down vote a post and I accidentally clicked the Up button. The opposite thing might happen. Can you make the Up, Down buttons not to look exactly the same?

By the way I found one of my posts that I did back at 2008! to be down voted even though the post contained a clear solution to the problem of the OP. I know that like the rep points, anyone can give you whatever points they want, negative or positive, but I find it strange that someone decided to down vote a post that is 1 year old without a single explanation.
At least with the reputation system you get to describe the reasons for your selection.

Thank you for your time.

majestic0110 commented: I totally agree with you there +0
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I haven't look at your code but from your explanation, I assume that you create the second frame, when the button is clicked?
If yes declare the second frame as global variable and create it once. In the previous way you keep creating a new one.
With this way whatever you do to the frame will be applied to the same instance:

class Frame1 extends JFrame {
  private Frame2 frame2 = new Frame2();

  // now you can set to visible false or true the frame2 whenever you want
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public static float average(short [] grades) {
  // calculate the average using a for loop
}

And to call it after you have your array created and entered values in it:

short [] grades = .... ;
..
..

float avrg = average(grades);
BestJewSinceJC commented: Congrats on 200th solved.. :) (Well marked solved anyway) +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't think it's possible. Whenever you type something it is stored in the variable, therefor you need an if statement, but I would suggest to wait for other people responses as well in case someone has a better answer.

Actually there is something that can simulate that.
Write a thread that keeps running in parallel with your main. Whenever you read the input set a local variable defined in the Thread. The Thread in its run method will keep checking the value of that variable in an endless loop. If "quit" is found you will break from the loop and call the quit in the run method.
Although you will need to be careful not to leave any unfinished business in the main, so you might want to pass more variables to the Thread from the main, so it will monitor the state of the main

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry for my double post but when you are done with your solution, there is a much smarter - but more difficult - way you can try:

String [] words = {"Alpha", "Bravo", ....};

Now when you get each character you can use its ASCII equivalent, then normalize that value to be between 0 to 25 and use it as index. In that way you will not have to write entire code with if statements:

char ch = stringArray[i];
int index = // convert ch into an int and normalize
System.out.print(words[index]+" ");
_dragonwolf_ commented: Thank you greatly +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you tried using another attribute than "disabled".
The input "text" has an attribute "readonly". Search what other attributes the checkbox has.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

java programming is the latest program around the world.
i am a student of computer programing our assessment are too near, i need to learn java programs in just four days starts from tomorrow ... could you?

Providing private lessons is not what we do here. Check the Read Me thread with the tutorials on top of this forum, and we will answer specific questions about any errors you might get with your code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In case you haven't noticed we have October. Tanning is out of the question, unless you plan to use the application at the South hemisphere.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How do I convert the Integer to String by:
1. Asking the user to input the number (Eg: 704 = Seven Hundred and Four)

2. Display the output in JTextArea.

Thanks for your support.

Start a new thread. This is a 3 year old thread.

Salem commented: Now it's 5 years old, but the bottom feeders are still here +17
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

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

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

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
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

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
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am sorry for being late to respond to this.

Firstly if you read all of the posts related to that particular question in both threads (the poster created 2 threads),
you will reach to the conclusion that the poster was accusing the programming language because he couldn't get his program to work they he wanted it.
Unfortunately this command hasn't been invented yet:

main() {
  runMyProjectTheWayIWantItToRun();
}

Secondly those who have replied, including me have suggested to and12 to post his code with relevant questions about his problem, as proposed by the forum rules. Not a single post contained code for us to look and comment

And lastly,
as VernonDozier said:

"Incompetent" means "not compotent in Java at this particular time"

I didn't called you directly "incompetent", I said:

...., for your incompetence

Meaning for your incompetence in java

It is different

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if it is possible to get the "My Computer" as root, but check this out:

File [] files = File.listRoots();
        for (int i=0;i<files.length;i++) {
            System.out.println(files[i]);
        }

This will get you all the files that are under the "My Computer". So instead of having one root ("C:/program files"),
you can create one father, and under that father put as nodes the "Files" that the above code returns:
C://, E://, D://

I don't know if it makes sense, but you can have this:

root = new DefaultMutableTreeNode("root", true);
 
          File fList[] = File.listRoots();
          for(int i = 0; i  < fList.length; i++)
              getList(root , fList[i]);
          }

After all, under "My Computer", all you have are the drives of your computer: C:/, D:/

Also you can check this tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

And I would suggest not to populate the tree recursively because it takes awfully long. Try to put Listeners and when a folder is clicked, then take and add the children.

Question: Have you tried JFileChooser?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The only bug I see is you accusing a programming language which has been around for decades, used by thousands, for your incompetence.

Just because you can't get it to work doesn't mean it has a bug, it means you don't know what you are doing.

It is OK not to know, it is not ok to say that "java" has a bug when no one else has complained just because you rushed into doing something without the proper experience

This simple example can be found anywhere:

JButton butt = new JButton();
JTextField field  =new JTextField();

public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
  if (source==butt) {

  } else if (source==field) {

  }
}

That is how you know what was clicked

tux4life commented: Yup, you're a legitimate owner of a 'Featured' badge :) +21