javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

guys, help m plz.. i need a java code that separate a number from words..

Be more specific, start a new thread and show what you have done so far

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Create the image object from the file, then create an ImageIcon frmo it and the set the button's icon with that icon.

Image myImage = getToolkit().createImage("myImage.jpg");
ImageIcon myIcon = new ImageIcon(myImage);
myButton.setIcon(myIcon);//here you set the icon for your button

If you had read carefully his question, jemz has asked how to make the image smaller in order to fit, not how to put an image in a button

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all write the code like this. Change the names of the classes to Capital first letter.

import java.util.*;

public class AcountBank {
    private  static Hashtable ht=new Hashtable();

 public static boolean  search(Information o){
   if(ht.containsKey(o)) return true ;return false;
 }
   public static void  add(Information o){
      ht.put(o, o);
  }

}

Since the methods and variable are static, you don't need to create a new Object. You do that for non static methods and variables. for the above:

AcountBank.add(...);
AcountBank.add(...);

boolean b = AcountBank.search(...);

Second for the above to work you will need to override the equals method in the Information class: Object.eqauls()

Third since you are using as key and value the same thing, the object Information, why don't you use a Vector. It has similar methods that you can use

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

where?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In a previous post you used a method that allows you to take the value of a specific cell. It takes 2 arguments (the row and the column). What is wrong with using that.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi
im doing my final year in engineering in that we have to undergo a project. i am doing text search that is if we give a name like sachin and if that word present in that folder it has to display its content. how to do this?

Also start a new thread with some code since in this thread there were some suggestions.
If those do not cover you, make your question a little bit more clear

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You want to save what is at the jtable to the database. And just because you can't get the data from the jtable you insert null values and wonder why you get the exception?????

In previous posts you have been told how to get the values from the jtable. Have you looked at the API of JTable?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You got that exception because you tried to insert null values at the database. The variables of the instance you passed as argument are null. You need to give them the values you want to save

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to use capital first letter for classes:
Visit
Also don't give a method the same name as the class name. It can be confusing.


From that I understand it is not passing any values.
what can I do now

Also if you look at the code you are calling the method save with argument the visit object:
savmthd.save(vInfo)
The values that the vInfo has will be saved in the database.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I didn't know that this was possible. Good.

import static test.Test1.cons;

..

System.out.println(cons);

I usually do it like this:

System.out.println(Test1.cons);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Create a class with name, age, ... as attributes. With each loop create that object and put it into a Vector.
Then write code that displays the values of the Objects inside the Vector at the table

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

is any one there to help me? i need to know how a text folder is searched using java..
.

There is no such thing as a text folder.
Also start a new thread with some code since in this thread there were some suggestions.
If those do not cover you, make your question a little bit more clear

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

will work

Thank you for repeating the solution I gave 17 hours before your post!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I created the 3 other classes and run the code. It works, it prints the values of the array at the console.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Usually an ';' is added at the end of each command, such as this:

System.out.println("yes")
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For debugging try whenever you add anything to the list to print it as well as the element entered:

Student stu = new Student(passStudentName, passGrade);
people.add(stu);
System.out.println("Student:"+ stu);
System.out.println("People:"+ people);

Do that for all cases and try to add a person and see what happens. Also I trust that you have overridden the toString method in those classes (Student and Person).

Also if you want us to test that code, we will need all of your classes, but try first those suggestions and see what happens

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just a small addition to this issue.
We have been having some problems in displaying Greek character at the excel generated and after some tests it was discovered that in order to do that this tag also needed to be added at the <head> of the page.
Without it, it only displayed English characters:

<%@ page contentType="charset=iso-8859-7"%>

<%
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
%>


  <head>
        [B]<meta http-equiv="Content-Type" content="application/vnd.ms-excel;charset=UTF-8" />[/B]
  </head>

In case someone else is having the same problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

JavaAddict: Good suggestions but for the one suggestion, it shouldn't matter if he implemented equals() since he is using the removeAll method. Right?

He is not using a removeAll method with no arguments. Perhaps you didn't notice but that method takes as argument a collection and removes those elements that are inside the collection.

BestJewSinceJC commented: Yup, agreed now :) +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have the method that returns the selected row and the method that allows you take the values of whatever cell you want. And you have showed in your code that you know how to use them. The rest should be easy. It is only common sense

And by the way, are the cell already editable with defaulttable model or do I have to write codes to make them so

I don't know. It is your gui, have you tried to see if you can edit them?

Insert isn't a query, its an update. If I were to do that at the database I'll just be inserting the records manually.

Insert and update are both queries. And I didn't tell you to run all your queries manually. You have a query at the code that doesn't run. Have you tested it? I simply said, try to print the query and the values in order to run it at the database and see what is wrong with it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if this will fix your problem but have you tried to declare the method like this:

boolean removeAll(Collection<Actor> c)

Also in order for the "removing" to take place, java compares the elements in your list with the ones in the Collection in order to remove them. I order to compare them it checks if they are equal with each other. If yes it removes that element. So it uses the "equals" method. If you haven't overridden that method in the Actor class then the "equals" of the super class Object will be used which checks if they are the same instance, not if they have the same values.

Have you overridden the equals method in the Actor class?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

thanks but that's why i seek for help, i am not as good as you are so please just help out ok.

Compare these:
insertDetails(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,java.lang.String,int)

insertDetails(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,javax.swing.JLabel,java.lang.String,int)

One is the declaration. Don't you know you should call methods with the arguments they are declared.

You are not calling with the right arguments. Check the declaration and call it with the right arguments

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What about the following line (which is valid CSV) a,"b,c","d""e""f,g",h which should be

a
b,c
d"e"f,g
h

That's why you should look for a library, or you play around with indexOf and substring yourself (which I have been forced to do).

Ok.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The JButton takes as argument an Icon.
If you look at the class ImageIcon which extends Icon you will find 2 things:
The constructor of ImageIcon takes as argument an Image object.
There is a method: getImage() that "Returns this icon's Image."

The Image class has the method that you need to accomplish what you want.

Use that method to get the new Image, create a new ImageIcon and pass that as parameter to the JButton contructor

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At the line:
obj[0].current=0;

Something is null. You forgot to create the object that you are using.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You still need to create a File object if you want to read it. How else will you?
Have you tried to look at the API of the classes mentioned and follow the steps provided?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Search this forum to find how you can read any file line by line.
Then the String class has a method what will allow you to separate the line read like this:

line -> aaa,bbbb,cccc,
into this:
aaa
bbbb
cccc

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Is this correct?
String format("%-10",name)

Try to use System.out.println() and try to get the proper alignment and then when you are satisfied save it to the file

Try to read the API of the classes you are using in order to find what other methods you might use

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because the toRemove, doesn't have an Element actors:

toRemove.removeAll(actors);

Look the API, it removes the element you put as input. I assumed that added Actor instances, not Collection instances.

Also look at the API for a better description

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Using the 'lastIndexOf' was a good idea. In that way you can handle inputs such as: "file.name.txt";

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

how to get it to begin after the index.

Being able to figure that out has nothing to do with your knowledge of java. It has to do with you being able to think.

Everything you didn't know about coding has been said. There is nothing else I can tell you regarding the coding. You know which method to use and what it does.

Now it is time for you to think and show how smart you are.

BestJewSinceJC commented: Ballsy thing to say, however, much more helpful to OP in the long run. +4
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Tried the print result and still no go. I really cannot find a way to get rid of the . in this API stuff. I can get it to stop at the . and show the first word but i cannot get rid of it at the end. i may have to ask my teacher on this.

Read what the subString(int) method does. Forget about the 'index' variable and what it has.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

yes, that is correct, i am actually using the JOptionPane so i have a UI or dialog box but yes it still does that.

Forget the JOptionPane. Try to print the right result first.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Looking for the last letters. So if its hello.java, i just would like java to come out. im still stuck with that dang . in there lol.

So when you call this:

System.out.println(In.substring(index));

You get:
> .java

Then read again the substring(index) API and see how you can change the argument.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am looking over the API's and the substring can use 2 integers except when i do something like String one = In.substring(index, 0); its out of reach but if i do String one = In.substring(0,index); it gives me the first letters i have typed. Just trying to figure how i get the last letters/extension without the dot.

You want the first letters or the last letters? I thought you wanted the first. Anyway. Try to print these:

System.out.println(In.substring(0,index));
System.out.println(In.substring(index));

If you want the last letters without the '.' then it shouldn't be too difficult to understand which one to use and how, provided of course you have understood how they work.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Good you are on the right track.
I believe that you got rid of the NullPointerExceptions.

But you haven't looked very careful at String API for the substring methods.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have the substring there, yet i still get errors. I dont think it knows where to end the substring and i dont think it will work when my input and output strings = null.. i get errors when those are there.

You know "where" the '.' is. Look again the substring methods and stop using variables that are null.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Every time you call a next method, try to call afterward the nextLine() command.
whenever you do this:
> next()
> nextDouble()

You read the next input but you don't change the line. So the next call will not read what you entered, but what is left until the end of the line which is an empty String.

Or try this ALL the time:

import java.util.Scanner;
public class Lab1
{

	public static void main(String[] args)
	{


	   //	create a Scanner object
		Scanner sc = new Scanner(System.in);


	   // read a string
		System.out.print("enter product code: ");
		String productCode = sc.nextLine();

	  // read a double value
		system.out.print ("Enter price: ");
		double price = Double.parseDouble(sc.nextLine());

	  // read an int value
		system.out.print ("Enter quantity: ");
		int quantity = Integer.parseInt(sc.nextLine());
			{

	  		//perform a calculation and display the result
			double total = price * quantity;
			System.out.println();
			System.out.println(quantity + "" + productCode
			+"@ " + price + "=" + total);
			System.out.println();
			}
	}
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well i have the Output.substring() but i have no idea what i put in between the ().. do i put Index, our Output or find. Ill let ya know if i figure it out

The exception tells you the line and that you are using something which is null. As for the other: READ THE STRING API FOR THAT METHOD.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The exception tells you where the error is.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have the index of the '.' like I showed you. Now use the substring method to get the part of the string that you need. Then display in any way you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At the line specified you are using something which is null.

Like I said, at that line something is null. Not to mention that you messed up with the opening and closing of the parenthesis.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The indexOf will tell you where is the '.' dot:

String s = "abc.txt";
int index = s.indexOf("."); // 3
// a b c  .
// 0 1 2 3

Then use that index as parameter to another method of String that returns what you want.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you looked at the String API?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

correction it throws
Exception in thread "main" java.lang.NullPointerException
at LinkedStringLog.smallest(LinkedStringLog.java:187)
at CMPS39001.main(CMPS39001.java:121)

At the line specified you are using something which is null.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

CustomerInformation.java:164: insertDetails(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,java.lang.String,int) in CustomerInformationServer cannot be applied to (java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,javax.swing.JLabel,java.lang.String,int)
String result = chi.insertDetails(cid, name, dateOfBirth,

The error tells you exactly what you need to fix. Look carafully how you declare the insertDetails and how you are calling it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

does it compile?
have you compile it?
what is your code?
how do you run it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

what code are you using?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

what errors?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

registered iana media types (and a link to a registration form)

I also found that link but I cannot open it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That's a job for a servlet, not a jsp.

The correct content type is the one registered with bodies like the w3c, not one that someone cooked up in his head because he thought it "sounds kewl".

I used this and it worked
application/vnd.ms-excel

But I found in various sites other options as well:
http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html
Search for "excel"

But the quote from the article I posted said that only the one I used is the correct one.

So is there any difference between the one I used and the others, or it is like you said, someone came up with these names and they never worked?