javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Does it compile?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

have you got solution ? because i also messed up with same problem and dont know how to fix it. if you got solution please reply.

It is not necessary to have a css file, but if you use this value:
css_xhtml
and you right click the page to View the Source code you will see div tags automatically added with some default class names. You can add your own class names in the tags but if you omit them the defaults will be added.
Then if you want you can create a .css file with the default class names, and you won't have to worry about adding the class or the id attribute to your tags anymore. And all your application will have the same look and feel.

Also I don't remember where to put the properties file. It's been a while. But you should be able to search the internet on how to deploy and run a Struts 2 applications or by simply searching the struts.properties

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Okay, i haven't started coding yet...but can you tell me the code how i can prompt the user to enter names, and than put them in alphabetical order and outputs them using sorting, thats it. thanks

You will find plenty of examples in this forum on how to use the Scanner class.
Also check the API for the Vector or ArrayList for storing the input.

If Scanner class doesn't work, post the errors you are getting, because it works for java 1.5 .

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think you should keep your code they way it was and return the index where the target element was found. Without increasing it by 1. In your methods you should always return indexes the way they are. 0 based. In java indexes begin with zero. Don't change that. If you want to add 1 do it after your program returns the value when you print int.

Not to talk about your problem. Keep the code the way it is and find the index where the target is. Then outside the while loop, after you get the index, search the neighbor elements to see if they are equal with the target.
First start checking the ones that are lower than the index and keep reducing the index until you find something that is not equal:

int index;
while () {

}
// found target at index
int tempIndex = index;
while ( ([B]tempIndex>=0[/B]) && (userArray[tempIndex]==target) ) {
  System.out.println("Found at: "+tempIndex);
  tempIndex[B]--[/B];
}

// do the same by increasing the index. Careful with the expression at the while loop

All it is left to decide now is what you want your method to return and how.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes:

This can be changed by adding a file:
struts.properties with the line:

> struts.ui.theme=css_xhtml

The above changes the way the tags would be rendered. The default is this: xhtml. If you use this: simple the tags would be displayed the way you write them in the code.

With the one I am using it generates <div> tags around the components in order to be easier to add .css style later

Also I think that you can set the theme at each tag that you write. But that is not very helpful. It is better to have it in one prop file.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post the part of the code where you get the exception?

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

ERROR:
non-static method isPrime(int) cannot be referenced from a static context

As the error says, You cannot call a non-static method inside a static method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you search this forum you will find examples on how to:
> Read a file
> Write to a file
> Use the split method
> Create objects
> Add them to Vector or ArrayList

And to make things simpler, don't try to put everything in the main method. Try to separate them in different methods

Edit:
There is also an example on how to create a menu using an endless while loop

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post the current code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For starters, use the .equals method to compare the equality of Strings and any other objects.
See what happens and I will look closely the rest of code later.

String s1 = "a";
String s2 = "b";

// examples

boolean b = s1.equals(s2);
b = s1.equals("ccc");
b = "abc".equals(s2);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks a lot for your suggestion. I also tried this and geting this abnormal behavior. I dont know whats the reason. Can you suggest a reason and how to rectify it . Actually I am writing a file with a blank line in its start, and then counting the no of line written afterward. I have to write an integer,i.e. the no of lines written in the file, in that blank line.Initially I was just writing the newline escape character("\n"). Due to this my next line was getting edited instead of inserting that in blank space. But then I tried to give some space and some tabs at beginning it will write that some no of digits. But if the no is too big it will again overwrite my data......
How to overcome this????

I don't know, never done anything like that before. You could try to put many spaces at the first line of the file.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then why this:

powerSeries = 1 + ....

and this:

radians - powerSeries

Just calculate this in the while loop: (- x2/2!) (x4/4!) (-x6/6!) Then subtract from 1

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you sure you have the right formula?
Also shouldn't you have this:

powerSeries [B]+=[/B] 1 +(negationFactor * (Math.pow(radians, expFact))/factorialResult);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Search the forum for examples on how to read files

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Before each row, meaning at the beginning of each row you need to print before the first '*' the spaces. How many spaces will depend on the row you are now. I believe it is the 'i' that counts the rows. So the 1st row will have 0 spaces, the 2nd row will have 1 space.
And I gave you code for printing spaces.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have found this link:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&lngWId=2
I don't know if it is helpful, but from what I understood, if the code runs at some other computer then you need to transfer not only the code, but whatever other jar files or library it uses.
Usually for mySQL you download a jar file that has inside the driver like the one you have: com.microsoft.jdbc.sqlserver.SQLServerDriver So you might want to get from your college the jar file or in what other form they use.

I assume that you have set the database at your computer.


Another code I found is this:

private static final String accessDBURLPrefix = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; 
private static final String accessDBURLSuffix = ";DriverID=22;READONLY=false}"; 

// Initialize the JdbcOdbc Bridge Driver 
static { 
  try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  catch(ClassNotFoundException e) { 
    System.err.println("JdbcOdbc Bridge Driver not found!"); 
  } 
} 

/** Creates a Connection to a Access Database */ 

public static Connection getAccessDBConnection(String filename) throws SQLException { 
  filename = filename.replace('', '/').trim(); 
  String databaseURL = accessDBURLPrefix + filename + accessDBURLSuffix; 
  return DriverManager.getConnection(databaseURL, "", ""); 
}

It uses a different driver than your own:
"sun.jdbc.odbc.JdbcOdbcDriver"

If you search the net you will probably find both.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Does this call executes correctly? Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Try to run it separately. If you want to get the connection you will need the above driver. And in order for the the Class.forName to "find it" you need to tell your program where that class is. I assume you downloaded a jar file?
Then you should be able to find instructions on the net on how to set it to your classpath.

Are you using some kind of IDE?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The problem is probably because it cannot find this class:
com.microsoft.jdbc.sqlserver.SQLServerDriver
when you call the Class.forName

Have you download and set to your classpath this driver: com.microsoft.jdbc.sqlserver.SQLServerDriver ?

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

Well I also thought but the thing is there are approximately 10000 lines of data, and each line containing 500 bytes of data . Again reading and writing file not be a efficient way. Isn't there any other option of doing that

I have never had to do that, but I believe there are some classes that enable you to do that. If you check the java.io API you might find something

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Statement is used when u have fixed query...
eg: select * from emp where eid=10...
this query will always provide a constant output..i.e. it will always retrieve the details of that particular employee whose id is 10
this kind of query is also know as hard core query...this kind of querying should be avoided...

Prepared Statement is used in case of dynamic data retrieval...i.e this is used for retrieving data as per user requirements at run time...
eg:
DataInputStream dis=new DataInputStream(System.in());
int no=Integer.parseInt(dis.readLine());

string query="Select * from emp where eid= ?";

[this "?" acts as a placeholder for the data to be entered by the user at runtime]

PreparedStatement ps=con.prepareStatement(query);
ps.setInt(1,no);

[here "1" stands for the first "?mark" to be matched with the user input number ==== as in our case we have only ?mark so no complications]

Callable statement is used for procedure calling or function calling...
i.e. if u have created any procedures or functions based on your tables in SQL server / Oracle....then through java api u can call them to perform some calculations n stuff....

please reply if this information was helpful to you...

thanks,
Jenifer

You just repeated what I just said.
Also you can have dynamic queries with Staments as I said in my post.
You can have dynamic queries with both Stament and PreparedStament but the latter is faster only if it is executed many times.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One suggestion is to read the entire file and then write again what you want at the first line and the write the rest of the data read

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The dashed borders appear whenever you select something. If you add a lot of buttons in a frame and you click one it is natural the it will appear selected.
I believe that these dashed line are to show you which element you selected.

My advice, although you will have to test since I have never done it before, is to add a MouseListener on the elements you want to remove the borders and whenever the mouseReleased is triggered to have the element "lose focus". For the last part you will have to check the API for the right method.

example:
For JButtons there is the setSelected method

Also look at the implemented classes of:
ItemSelectable

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

for-loop that adds spaces equal to the number of row currently printing.
Also use for loop to display the number of "*"

Displays N spaces

for (int i=0;i<N;i++) {
   System.out.print(" ");
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry I couldn't get it, would you make it a little bit clearer!!!!!!!!

Thanks

[EL-Prince]

What?
Wasn't this clear enough?

Learn manners first.

Who are you to demand?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There is any java Language Translation API. If so means, please indicate that API.

Please explain.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API.

p.addActionListener(new gameinit());

The JFrame class doesn't have such method: addActionListener.
Then search the API some more to find which elements accept an ActionListener (Buttons and such)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In order for this method to execute:

public void actionPerformed(ActionEvent e)
		{
			Izzy.hittable();
			Izzy.movement();

			if(rar == 'T')
			{
				System.out.print("Sky High(Grand Nuave)");
			}
		}

You need to add its listener to a component. The methods in the 'KeyListen' are executed because you do this:

p.addKeyListener(new KeyListen());

When you want the actionPerformed method to execute?
Also since it it the gameinit class that implements the listener, it is an instance of that class that you will add:

someComponent.addActionListener(new gameinit());
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well since you found the number you know one of the occurrences of the number.
Assume this:
You are looking for '3'

1 2 3 3 3 4 5

And you find the position of the "Red" 3. So all the others 3s will be either left or right from the position you found. Of course your algorithm might find this:

1 2 3 3 3 4 5

or this:

1 2 3 3 3 4 5

You need to search the neighbor positions to see if the target is there. Maybe another while loop before you return.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest to look for tutorials on all of them.
In sort:

> Statement for executing "raw" queries:

String name = "Name A";
String query = "select * from table_A where name = [B]'[/B]" + name + "[B]'[/B]";

// Use statement to execute the above query.

> PreparedStatement for parametrized queries:

String name = "Name A";
String query = "select * from table_A where name = ? ";

PreparedStament ps = ....;
ps.clearParameters();
ps.setString(1, name);
ResultSet rs = ps.executeQuery();

> CallableStatement is used to execute stored procedures. I don't have an example with me. Try searching the internet for the last one.

And check the API for all of them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually you should have something like this:

int index = 0;
for (int i=0;i<array.length;i++) {
  int num;
  // read int number
  System.out.[B]print[/B](num+" ");

  // loop again through the array to see if that number already exists
  if (doesn't exists) {
      // put it into the array
     [B]array[index] = num;
     index++;[/B]
  } 
}
System.out.[B]println[/B]();

The for loop above will not loop the array. Is a way to count the numbers given. For putting things into the array you will need another 'index' which you will only increase every time a new value is actually entered into the array.

The index value tells you how many value you have entered into the array:

[B]array[index] = num;
     index++;[/B]

At the beginning index has value 0. When you enter something it becomes 1. So you have 1 element and the next would be put into the '1' position.
Whenever you loop the array use the index to tell you how many elements you have.

After the above loop print the elements of the array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Aren't you suppose to do this:

dRetirement = keyboard.nextDouble();
[B]dGrossPay = [/B]grossPay(dHours, dRate);
//netPay(dGrossPay, dRetirement);

Instead of this?

dRetirement = keyboard.nextDouble();
grossPay(dHours, dRate);
//netPay(dGrossPay, dRetirement);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Don't get me wrong... I actually really liked Vista. Win7 however will give you much more bang for your buck - much lighter, more intuitive, cleaner by far. As for cost, look on line for OEM copies for sale.... if MS won't close that loop-hole, then make use of it :) Also, Win7 seems to have better compatibility with older apps, and Pro/Ultimate versions give the option of XP Mode (so long as your CPU supports it) for those more problematic applications.

As to drivers, in most case the Vista & Win7 drivers are often one and the same, but with Vid and Audio drivers, best to see if the manufacturer has released updated builds for Win7... not much leg work involved in that after all

Thanks.
But I will hold on to my Vista for now. I don't believe that I need it right now, but in the future when I decide to do a format, I will upgrade.
Your comments were very helpful.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi everybody,
I also have a question related to this matter and I hope I am not out of topic.

Me and a friend of mine bought a year ago new PCs with Vista installed. He is been telling me that he wants to upgrade to Windows 7, but I disagree.
I have a new OS and there is no point in spending more money to buy again another OS (Windows 7), because since it is that new the programs that I run might be incompatible.

What is your opinion on that?

Also since I am not that familiar with the procedures of installing and upgrading OSs, If I put Windows 7, will that effect my Graphics Card or my sound card? Will I need new drivers?

Thanks.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can check the API to see if there is a way to get the data from the table.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

quick start ....... try & u'll do it
:-)

Not quite correct when in fact there should be more arguments (3 different grades), and at the average you add the same grade 3 times.

But if your intention was for the OP to figure that out, I am sorry.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hi ya! im new to this kind of forum and didnt realise i needed to put up every thing id done already! of course ive done work lol! i was just looking for pointers in the right direction, my lecturer isnt very helpful and hasnt taught us very well :(

ill put up wot ive done in 5, then hopefully someone can help :)

thanks

You didn't ask specific questions, nor you mentioned what you have done. Posting your assignment will give the wring impression to others.

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

Try to better explain your problem. What you posted is difficult to quite understand.
Also, don't tell me that your teacher hasn't showed how to write a single class with attributes and get/set methods. Or don't you have a book or notes with examples?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I suppose by the time you have been given this assignment your teacher has showed you how to write programs and how to run them or how to declare methods ans use them. I assume that you have some notes on how to declare and instantiate classes, or how to create arrays and loop through them.

* each student should have a name, registration number, 3 module codes and 3 module marks
* the class constructor assigns values, passed as parameters, to the name, registration number and module marks. the module codes are set by a single method setCodes
* the class has 'access' methods getName that returns the student name, getAverage that returns the average mark of the students 3 marks and getHighMark that returns the highest mark of a student.
* the class has a set method to update the module marks. the toString method outputs full details of each student including the average mark and highest mark.

The above tells you exactly what you need for the Student class.

Now that you read the above, we expect to see some work, not excuses.

Also if you search this forum you will find many examples on how read input using the Scanner class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If I understood correctly whenever you click a button you need to get a value from a "set of values" depending on the value of the radio button?
If yes then you don't need any listeners to the radio buttons. Whenever a button is clicked, you can get the value of the radio selected and then with if statements select the set you want to take values from:

// When a button is clicked
actionPerformed(Action event) {
    // get the value of the choice button currently selected
   // with that choose which "set of values" you will use
}

Check the API. I assume that you use javax.swing.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Any other homework you need us to provide ASAP on your demand? Perhaps just post your instructor's email address so we can send it in directly?

Don't give him ideas. Once I saw someone here who actually did posted his teacher e-mail and asked us to send the code there!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

java extension are file.java

perhaps you should try to use eclipse to make your java codes

This thread has already been solved and you added no additional information.
Also using eclipse will not solve the problem but it will make it bigger because the user will not have learned a thing about java. Now he knows that compiled files end with .class and he knows how to execute them. And I assume he knows how to set the classpath.
If he had gone with eclipse, he would be running the code without knowing how .class files work or how to run a single java file. That is not learning.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It's not a big challenge. We can easily do it. Can you post something more difficult because I am bored?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well have you fixed the method?
Also for the example, I would suggest to go and just add the radioButtons in the table:

dm.insertRow(i,new Object[]{i+1,arr[0], arr[1], arr[2], JRadioButton, JButton,  . . . });

With the appropriate columns of course.

Have you removed the final from the DefaultTableModel. I don't think it's needed.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is not what I told you to change. Read carefully your initial for-loop. Then read my comments and then read your notes or a book about what a for-loop does and what its arguments do.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check this method and tell me what is wrong:

public void setTable(JTable table1){
  table1 = table;
}