javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you want that line to be appended at the end of the file, after the existing lines?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can have a method in the Student class:

public int comporeByGrade(Student st) {
    return grade - st.getGrade();
}

The above method will return positive if this Student is greater than the argument, negative if it is lower than and zero if their grades are equal.

So write a for loop that loops through the array. Take each Student and use that method in order to determine which Student is greater than the other and then use any of the sorting algorithms provided.


If the issue here is not to implement a sorting algorithm for educational purposes but simply sort the list using any means necessary then you can have the Student class implement the Comparable interface.
Then implement its method: compareTo and use the sort method of the Arrays class.
Of course you will need to convert the ArrayList to an array for the sort method of the Arrays class, but that shouldn't be a problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When the class is first "executed" the query variable has this value:

String query = "SELECT * FROM PatientTable WHERE Surname='"+ jtffreeQuery.getText()+"'";

The text, I assume is empty, so it like writting:

String query = "SELECT * FROM PatientTable WHERE Surname='' ";

h

But when you click the button, the value at the field has changed, but the value of the query hasn't. You don't change the value of the variable. It cannot change on its own when you change something.

It is better to do something like this:

QueryTable qtable = new QueryTable(jtffreeQuery.getText());
qtable.setSize(700,500);
qtable.setVisible(true);
public QueryTable(String input) {
  String query = "SELECT * FROM PatientTable WHERE Surname='"+ input+"'";

// continue with the rest of the code.
}

In that way, you keep the class parametrized.

PS: Don't forget to close the Connection

JBeginer7891 commented: Thanks JavaAddict! this has been very helpful. +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I wouldn't have done it that way, so I don't know how your code will behave exactly.
So the only thing I can think of is for you to change the:

row.addElement( rs.getObject(i) )

TO:

row.addElement( rs.getString(i) )

Also you are not closing the Connection object, unless I missed that.

Also this call: rs = stmt.executeQuery( PatientReg.query )
Never returns null ResultSet.
So you can have your while to be:

while (rs.next()) {

}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

yeah i am unable to locate the thing that is null, and the errors are inside the java fixed classes which i have in no way edited.

No you were too lazy to read the messages, as I told you. That is why you couldn't locate the error.:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.JComboBox.setModel(JComboBox.java:292)
at Application.UserManagement.initComponents(UserManagement.java:234)
at Application.UserManagement.<init>(UserManagement.java:52)
at Application.UserManagement$7.run(UserManagement.java:448)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 1 second)

Did I have to point that out to you? When you get any error, don't you even bother to read it, or just post the error and expect others to do it for you?

If you still can't fix it, then point out at the code where that line is. Although the problem is that you are using something which is null (you haven't initialized something) as stated by the exception and other posters:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you read the messages they tell you at which line you get the error and what the error is.
You are using something which is null

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That means defnitely Statement should implement ResultSet interface methods to return a ResultSet object

No, Statement doesn't need to implement ResultSet:

public interface Resultset {
 // some methods
}


public class SomeResultSet implements ResultSet  {
   // someone has implemented all the methods of the ResultSet
}
public interface Statement {
  public Resultset executeQuery(String s);
}


public class SomeStatement implements Statement {
  public Resultset executeQuery(String s) {
      SomeResultSet srs = new SomeResultSet();
// code to create the Resultset
     return srs;
  }
}

In the same way someone has implemented the Connection interface, so when you call DriverManager to get the Connection the implemented class is returned instead, in which there is the implementation that returns the implemented Statement.
In other words, java has provided only the interfaces and it's up to the database "vendor" to provide the implemented classes.
When you downloaded the mysql java connector jar, what do you think there is inside it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are not closing the prepared statement. Also you'd better post the entire code along with the loop and how you pass values to the statement as well as the query.
I think there might be a better way to do this

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hai!

First you read filname like (java.txt,java.exe....) as a first argument...

then check it string.endwith(".txt");

if its then you get next argument like..("this is txt file","have a nice day"...)


split(" ") can do but it will split every space as another string...

it is better to get input as every line ...until you wish to quit...

In the first post the OP said that each line has the file name and the description. I assume that this is the requirements. He said that the line would be like:

list.txt This my shopping list
Blip.class A Java byte file

As far as using this call:

String f = "abcde";
System.out.println(f.contains("bc");
System.out.println(f.contains("de");

There is always a VERY small posibility that the description might contain this: '.txt'

A better aproach, than my initial would be this:

String s = "Blip.class A Java byte file";
int index = s.indexOf(" "); // returns the first occurence of " "
String file = s.subString(0,index);
String des = s.subString(index+1);

If you use the split(" ") method at the above String, as I wronlgy suggested, the line : "Blip.class A Java byte file" would be splitted into 5 tokens. You could of course take the first token and concat the rest, but it is not very efficient.

Don't forget to check the String API or any other class's API you are using.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the classes:
SimpleDateFormat,
Calendar,
java.util.Date

Read their API

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The method: String.split() Check the API:

String s = "a b c d";
String [] tok = s.split(" ");
System.out.println(tok.length);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I haven't tried that before but there is the next() method:
Call the method twice and give 2 numbers as input:

String a = scan.next();
String b = scan.next();
[B]scan.nextLine();[/B]

double num1 = Double.parseDouble(a);
....

The input would be:
>20 30


A small explanation about the addition of the scan.nextLine() command.

When you call the next method you don't change lines. So you can read the 2 numbers. But any other call of the next.... methods will be done at the same line. It will try to read what is after the "30". Which is an empty String.

If after the second next, you press ENTER and try to read the next line with the nextLine or any other nextDouble method it will not read the next line because the "cursor" is still at the line with the first 2 numbers: "20 30". It will read from the last position it was(after the "30") till the end of the line. Which is, as mentioned, the empty String "".

That is why you call the nextLine in order to change lines. Unless of course you want to keep entering numbers

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you search this forum you will find an example that uses this command:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is possible but pointless. If you want to call the class program to get the answer, then just put what is inside the main to a separate method with arguments and call that method.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks! but as I said in my previous post its contents are shrunk in the center. I mean how can make the width of the Jtable and the jscrollPane wider so that the columns are not shrunk?
Thanks for the support.
Here is the code

//Do search button
    Searchbtn = new JButton("Search");
    Searchbtn.addActionListener(new ActionListener(){

        public void actionPerformed(ActionEvent e){

           try{
            // Connect to the database
            Connection connection = DriverManager.getConnection(url,userid,password);
            Statement statement = connection.createStatement();
            // the query
            ResultSet rs = statement.executeQuery("SELECT * FROM PatientTable "
                        +"WHERE Surname = '"+ jtffreeQuery.getText()+ "'");
            String[] tableColumnsName = {"Patient No","FirstName","Surname","Location","D.O.B", "D.O.R",
                                         "Race","Gender","Status","Initials","ID Number"};
            DefaultTableModel aModel = (DefaultTableModel) aTable.getModel();
                aModel.setColumnIdentifiers(tableColumnsName);

                if (rs!=null){
                    // Loop through the ResultSet and transfer in the Model
                    java.sql.ResultSetMetaData rsmd = rs.getMetaData();
                    int colNo = rsmd.getColumnCount();
                    while(rs.next()){
                        Object[] objects = new Object[colNo];
                        for(int i=0;i<colNo;i++){
                            objects[i]=rs.getObject(i+1);
                        }
                        aModel.addRow(objects);
                    }
                    aTable.setModel(aModel);
                }else{                aTable.setVisible(false);
                JOptionPane.showMessageDialog(null, "Record Not Found!");
                }
              if(rs!=null) rs.close();
              if(connection!=null) connection.close();
              if(statement!= null) statement.close();

            }catch(SQLException evt){
                evt.printStackTrace();
            }
        }
    });

You have started another thread with the same question. Try the suggestions there and also check the API for JTable

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try to add some System.out.println in order to see if the data have been read:

JTable table = new JTable(data, columnNames);
// use for loops and print the data the the varaibles: "data", "columnNames" have

Also try this:

JTable table = new JTable(data, columnNames);

JScrollPane scrollPane = new JScrollPane( table );

JPanel panel = new JPanel();
panel.add(scrollPane);

getContentPane().add(panel);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't get what values would they return?

As explained before you don't need to declare them (conn, st, rs) globally. You will have separate method where you will declare these locally, use them, close them and that is it.
You can have those methods in another class, if you want, but the idea is to call those methods and at the place you call them, you are not suppose to bother with "database stuff":

public method() {
// do database stuff to get the data
// open , close connection, ....
}

....

{
  // call the method somewhere else
  // simply get the results, like the getPatient method
}

Also in your previous question, one record is left out because you call the rs.next twice and you don't get for the first call any data:

if ([B]rs.next()[/B]){
  java.sql.ResultSetMetaData rsmd = rs.getMetaData();
  int colNo = rsmd.getColumnCount();
  
  while([B]rs.next()[/B]){
     // get the data
  }
}

As you can see the first time you call rs.next, you only take the ResultSetMetaData. Then when you call rs.next() again and you skip the first row you read.

In the Searchbtn.addActionListener code you have, again you are using the global Connection and statement. I don't see them being closed anywhere!!!
Remove the global declarations. Initialize them there locally and after you are done, CLOSE them, as well as the ResultSet

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the same way you are saving and reading the file your are using now.
Only this time the other file will have data like:

color=255,0,0
// or color=red
font=5

And others. When you read the file with the text, you will also read the second file. Take the data and apply the style.

You should use BufferedReader in order to read the second file line by line. You will also use the String class to separate the name from the values:
color=red

For the file name, if the text file is called something like:
file.txt, then you can have the other called: file_style.stl

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i am typing some content with some styles and saving it,when i open it again i am unable to see the font styles which i have specified to them.

That is because you are not saving the style. How are you suppose to see it?
You can try to create a separate file,for each text file, in which you will save specific information of the style. When you open the text file, also read the "style" file and adjust the fonts accordingly

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you are saving the text area to one of these files then they don't have fonts and sizes. That is up to the editor you are using to view the file.
.txt for example doesn't have colors.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

NullPointerException at
at candidateinfo.VotersTableList.setTheCandidateTable(VotersTableList.java:90)
at candidateinfo.CandidateList.showList(CandidateList.java:60)
at gui.VotesForm.showJButton2ActionPerformed(VotesForm.java:154)
at gui.VotesForm.access$200(VotesForm.java:22)
at gui.VotesForm$3.actionPerformed(VotesForm.java:77)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6134)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5899)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
at java.awt.Container.dispatchEventImpl(Container.java:2067)
at java.awt.Window.dispatchEventImpl(Window.java:2458)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

The exception tells you at which line something is null.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In what kind of file are you saving it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And your question? The code seems to work

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hi can i see the code of number to words conversion
plzzzzzzzz
tnx aineed it asap

What do you mean by that? If you can see it then what is the problem?

To >> ss999
This thread already has sample code for the conversion.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After checking the API you can use these methods:

table.setSelectionBackground(Color.GREEN);
        table.setSelectionForeground(Color.RED);

        table.setRowSelectionInterval(1,1);

The setRowSelectionInterval selects the rows between the first and second argument. The above will select the row 1. And since you have used the setSelection.... methods, you see the pretty colors

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

But those global connection, statement and resultset are used by other methods in the class.

Are you closing them? Because in your code, you call the getPatient, inside you have a ResultSet which you declare and close, and outside you are using another ResultSet which has no data inside, even though you already got the data.
My suggestion is to have methods that Declare the above (connection, statement and resultset), "open" them, "close" them and return the results.

You are not gaining anything by having them global. They shouldn't be in the same class. You should have another class with those methods, that return only results

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I did some testings and when the gif is static then it displays correctly. I had a problem displaying the gif when it has motion. The image displays in the jTable, but it is not moving and when you click the cell then it changes what it displays, but it doesn't have motion. Meaning that every time I clicked another cell and then the image, the image changed what it displayed but it was not moving like it was in your post.

I tried putting it in a JLabel and simply display the label somewhere in the jPanel, outside the table and it was OK.

So 3 Solutions:
1) Use static images and put them in the table

2) Don't use table if you don't have to. You can use GridBagLayout that allows you to put components (buttons, fields, labels) organized and have one of these to be a JLabel with the moving image. Meaning that with the GridBagLayout you will place your components on the jPanel to look like they are in a table

3) Don't listen to me. Just because I couldn't do it, doesn't mean it can be done. Try to search a bit more and find how to put moving images in a table.


And one last general suggestion.

The RecordShow class you created wasn't suppose to do anything but extend the AbstractTableModel. The idea was to do only that and call it from another class. Don't …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have a method: Patient pt = getPatient(ptNo); which executes correctly, you call it and you get the patient info.
You are calling the method that brings you the data you want.

Then you call the rs.getString("..") again, outside the method, after you acquired the data
Why?

Delete all the global declarations of Connection, ResultSet and Statement.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you saying that the image appears but is not moving? If yes, can you attach it so I can do some tests with it?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For 2D arrays

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all about this method:

public Class getColumnClass(int col) {
   return ImageIcon.class;
}

You define data:

final Object[][] data = new Object[][] {
{
  ("qwer"),
  ("qwer"),
  ("qwer"),
  new ImageIcon("C:\\Temp\\b020.gif")}//atr.gif
};

The first columns are String and the last is ImageIcon. But your method always returns ImageIcon.class. That method needs to return the class of the object that each column has. You need to do something like this:

public Class getColumnClass(int col) { 
   if (col==3) return ImageIcon.class; // column 3 has ImageIcon
   return "".getClass(); // the rest are Strings
}

Or better, assuming that data has at least one row:

public Class getColumnClass(int col) { 
   return data[0][col].getClass();
}

Also I noticed that you need to add columns and rows to the table. A simple example on how to add more rows. First you mustn't have data to be an array. You initialize the AbstractTableModel with an array, which is static. Meaning that is difficult to add more rows than the ones already there. If you need to add more rows then you need to make sure that the methods of the AbstractTableModel return those rows. Why don't you try this:

public class CustomTableModel extends AbstractTableModel {
    private String[] columnNames;
    private Vector<Object []> data;

    public CustomTableModel(String[] columnNames, Vector<Object []> data) {
        this.columnNames = columnNames;
        this.data = data;
    }

    public int getRowCount() {
        return data.size();
    }

    public int getColumnCount() {
        return columnNames.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Object [] obj = data.get(rowIndex);
        return obj[columnIndex]; …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hello!
i need to create JTable which swing string and animated gif image also...
how to put animated gif and data(string) in Jtable cell dynamically...
can you give any referel link or codes...
i tried lot but vain...

What have you done so far?
http://www.daniweb.com/forums/thread251668.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Fist of all print the query and run it directly at the database and see if it runs.

Then, create a new class with one main method. Inside do this:

public static void main(String [] args) {
  Connection conn = null;
  Statement st= null;
  ResultSet rs = null; 

  String query = "select * from PatientTable where patientNo = '123'";
  // select * from PatientTable where patientNo = '123'

  try {
       Class.forName("your driver");
       conn = DriverManager.getConnection(url, userid, password);
       st = conn.createStatement();
       rs =st.executeQuery(query);
  
       if (rs.next()) {
           System.out.println("Found");
       } else {
           System.out.println("Not Found");
       }
  } catch (Exception e) {
     System.out.println("Exception e: "+e.getMessage());
     System.out.println("----------------------------");
     e.printStackTrace();
  } finally {
     try { if (rs!=null) rs.close(); } catch (Exception e) {e.printStackTrace();}
     try { if (st!=null) st.close(); } catch (Exception e) {e.printStackTrace();}
     try { if (conn!=null) conn.close(); } catch (Exception e) {e.printStackTrace();}
  }
}

Try to keep the finally the way it is; close them in that order. (Actually I don't know if the order that you close them makes a difference but just in case follow that order.)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You cannot create a javascript application in java, because javascript is not java, it is javascript.
You create javascript applications written in javascript.
And the javasx.swing package is for desktop applications. It has nothing to do with the internet.

I suggest to forget what you want to do for a few years.
From the code you wrote you don't even know good java.

Clear your thoughts. Decide what you want to do specifically and read some books on that. From what I read, you don't even know what you want to do.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you mean when you say preview window?

When you do onmouseover, you can take the src of that image and set it to some other image:

<img src="...." onmouseover="document.getElementById('[B]target[/B]').src = this.src" 
onmouseout="" />

<img src="" id="[B]target[/B]" />

For a complete reference:
http://www.w3schools.com/jsref/dom_obj_image.asp

The above link has the properties of the image object which you get when you do:
document.getElementById('target')

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In a few hours I will give you a more detailed suggestion. For the time being, can you run the code again, and post the entire exception stack trace.:

catch(SQLException exc){
  exc.printStackTrace();
  throw exc;
}

Also there would be some line numbers. Go to those files the lines refer and post those lines as well. Of course you will post only the lines of your classes, because the stack trace will print and other class lines as well.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi all,

many thanks for all the help.

JavaAddict: I ended up using with the following (don't know if it was the best way to go about it, but it worked):

Object itemA = inComboBox01.getSelectedItem();

To be fair I have a lot of learning to do. I'm going through some books now.

Thanks all for the help.

Actually it is the same thing. But if you wanted to do more manipulations you would need to cast the object returned to its class. Meaning that if you don't use the gui builder to add items to the combo box, you can use the add item method that takes as argument an object. Any object. Then with getSelectedItem you will have that object and all the data it has:

Try this:

class Person {
  private String name;  
  private int age;
  private String phone;

  public Person(String n, int a, String p) {
   name = n;
   age = a;
   phone = p;
  }

  // get, set methods
}

Then create an empty JComboBox and go to the code and do this:

comboBox.addItem( new Person("Name 1",10,"111111") );
comboBox.addItem( new Person("Name 2",20,"22222") );
comboBox.addItem( new Person("Name 3",30,"333333") );

And see what it prints.

Then go to the Person class and add this method:

public String toString() {
  return name;
}

And try to see again the combo box.

Whenever you want to get the selected person just do:

Person pers= (Person)comboBox.getSelectedItem();
// now you can call the getAge and …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

CandidateList must be global. Every time you click something you create a new one, which is, of course, empty.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

root cause

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

It cannot find the class com.mysql.jdbc.Driver. You need to download the mysql-connector.jar and set it to your classpath. That jar contains the class you are missing: com.mysql.jdbc.Driver.

And for the rest of your questions, if any, please start a new Thread.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For overloading constructor:

private String Jazz;

    public JazzBandsInstruments(String p_Instruments, int p_Members, String p_jazz) {
        super(Instruments, p_Members);
        setJazz(p_jazz)
    }

Apart from that does the code compiles?

Make a list of all the requirements and check your code where they are implemented. If there is something you are not doing then post specific questions.

Then in your main just call the constructors and the methods. I would suggest, since you have more than one constructor per class, to make 2 instances of each object:

JazzBandsInstruments j1 = new JazzBandsInstruments();
j1.set...();
j1.set...();
j1.set...();
// print

JazzBandsInstruments j2 = new JazzBandsInstruments("arg1", arg2, "arg3");
// print
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you have read what you just posted you would have seen that is says:
d1.jsp:27
NullPointerException.

At the above line you are using something which is null

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

in jsp,i created login.jsp. in login.jsp,i created username,password and submit button. my login.jsp goes through database.
i am okie BUT i want validation in login.jsp which goes through database.

Then create a method that takes as arguments the username and password and checks the database for the validity of these values.

For more information you need to describe what exactly is your problem and where are you having difficulties with. Also you need to provide code with what you have done so far.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Closing input because I need only one pair. For example:

3
123
1234
12345

Output

YES
123
1234

or

1234
12345

or

123
12345

One pair, all couples do not need to be issued.

In that case break from the loops or exit the applicaton.

What happens when you call output.close() and then output.println("") afterwards?
Because that is what you do when you finish with the loops.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Create a JFrame with textfields for username and password. Check the API there is a class for passwords (JPasswordField I think)
Use the getText methods to get the inputs, For the JPasswordField read the API.

Then have a method that takes as arguments the username and password and returns true or false. Call that. If it returns true, instatiate a new JFrame that represents the page you want to redirect. Make that visible and the login page non-visible (use method setVisible(false))

javax.swing.*

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The thread is still on the server and is open, so anyone can respond. The answer will be helpful to those of the network the solution of that problem. Your comment is not smart.

Respond yes, But give away the answer no. This is not a forum where the memebers do other people's work

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I haven't tried that before but my first guess would be this.
If you see tha API for the JTbale model, there is a method called setModel that takes as argument a TableModel. Look at the class that implements that inteface: DefaultTableModel.
The method addRow takes as argument an array Of Objects. So you can do this:

// initialiaze them somewhere globally.
DefaultTableModel dtm = new ....  // see the API
JTable jTable = new ... // see the API
jTable.setModel(dtm);

...
...

Object [] obj = new Object[2];
obj[0] = "String value";
ojb[1] = new Icon();

dtm.addRow(obj);

Remeber when you get the values from the cells using the get Methods of the tableModel, you will need to cast them to the correct class

String s = (String)dtm.getValueAt(i,0);
Icon ic = (Icon)dtm.getValueAt(i,1);

And one last thing. The Icon class might not be correct. You need to check the API in order to find the correct class for creating image instances.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

A few corrections.
Since you do this at the loop: (j=i+1)

for ( int i = 0; i < n; i++ ) {
		  for ( int [B]j = i + 1[/B]; j < n; j++ ) {
			if ( numbers[j].startsWith( numbers[i] ) && [B]i != j[/B] ) {

You don't need to check if the i!=j. It will never happen. You make sure of that by starting j to be "i+1".
Another reason you initialize the j that way is so you will not compare numbers that have already been compared.
Imagine i=1,j=2 and comparing number[1],number[2] and then at the next loop i=2,j=1 and comparing number[2],number[1]
You avoid that

Also don't close the output in the if. Close them at the end of your program.
Also if the "YES" is printed, have a new variable take value true.
With your code, you will print "YES" in the if, but when the loops finish you will also print "NO". Have that variable take value "true" inside the if, and outside the "for-s" print "No" only if the variable is false.

And lastly don't use throws at the main method.:

// declared outside
  BufferedReader input = null;  
  PrintWriter output = null;
try {
   // initialized inside the try
   input = new BufferedReader(new FileReader("telefon.sis"));  
   output = new PrintWriter(new BufferedWriter(new FileWriter("telefon.out")));
  // your code here

  // close them last
  input.close();
  output.close();
} catch (Exception e) {
   // for debuging:
   // e.printStackTrace();

   System.out.println(e.getMessage());
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This forum is not for doing other's people homework. The rest of us didn't give the solution for a reason. We are not here to do it for them.

Ok you know the answer. So what? With your post you are implying that you are the smart one who posted the solution to a 1 month-old thread, which I find insulting for the rest,
And we are the stupid for not wanting to do someone else's homework so he can get all the credit without trying.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I took a closer look to your code and here is what I suggest.

First you need to read all the values of the array and then check for equality. You do this:

for ( int l = 0; l < n; l++ ) {
        numbrid[l] = sisend.readLine();
	for ( int j = 1; j < numbrid.length - 1; j++ ) {

You read the 1st number but then you loop the entire array. But the rest of the elements of the array are null.

I suggest to do something like this:

for ( int l = 0; l < n; l++ ) {
        numbrid[l] = sisend.readLine();
}

for ( int i = 0; i < n; i++ ) {
   for ( int j = [B](i+1)[/B]; j < n; j++ ) {
       // compare the values
}
}

Also check the index of the second (inner loop) I think that it is more appropriate. Remember that with each loop the first index increases by one. So if you want the second loop to look after that index don't set it to 1 but to i+1.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why don't you use: startsWith, instead of equals. Of course that means that for these the methods will return true:

1234
12345
"12345".startsWith("1234") = TRUE

1
123456
"123456".startsWith("1") = TRUE