javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

As each number is generated, check the current numbers array to make sure it does not already contain that number, if it does, just generate another.

I would like to add another suggestion. If I understood correctly, you have a pot with 49 numbers and you want to randomly select 6. When you select the 1st there are 48 left from which you want to select 5.
So I don't think it is 100% right to select again a random number from 1 to 49 and if it like the one already selected, to generate another. Because you want after the 1st selection the remaining 48 numbers to have the same possibility to be selected.

So here is my suggestion:
Have a Vector with 49 numbers and always generate a random number from 0 to Vector.size(49). Once generated, remove that number from the Vector and generate again another random number from 0 to Vector.size(48).
The number generated will be actually the index of the element in the Vector, so after a few loops they won't match (The number at index 3 will not be the number '3') but that is not important because the index and the selection will be random so you don't care how the numbers are sorted in the Vector.

Another way is to use an array of 49 numbers and when one of them is selected, "swap" it with the last element and randomly take a number from the first 48:

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try this:
Double click on your button. This will take you to the code page showing the click event.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Now all we do is add each button click to the back of this.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button3.Click, Button2.Click

And to find out which button was clicked check the sender object.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button3.Click, Button2.Click
        Dim btn As Button = sender
        MessageBox.Show(btn.Name.ToString & " pressed.")
    End Sub

I already knew how to do this, and even though I am new to VB, I know that this is not a good advice because you hardcode the buttons at the method Button1_Click.

If you have read closely, I have an array of buttons which is dynamically generated. So I cannot go and add at the end of the method the buttons, because I want the "handling" to take place at runtime.

I used Comatose's suggestion and did this:

For i As Integer = 0 To length - 1
  AddHandler Me.buttonEdit(i).Click, AddressOf viewEdit_Click
Next

Public Sub viewEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim buttonPressed As System.Windows.Forms.Button = sender
        MsgBox(buttonPressed.Name)
End Sub

By the way. Thanks Comatose. It was exactly what I was looking for.
To the rest of you thanks for your help.

And RamyMahrous the reason I am trying to write VB, is because in my …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi, as you can understand from the name, I am new in VB. So I have 2 questions regarding buttons:

1:
I have an array of buttons created like this in the code:

Dim buttons(10) As System.Windows.Forms.Button

I need whenever each one of these buttons is clicked to invoke the same method. Then I will go into the method, figure out which button was clicked and act accordingly. The reason I am doing this is because the length of the array will be created dynamically. So I don't know how many buttons there will be when the form loads, but I want when one of the buttons is clicked to call the same method

And 2:

I have written this code:

Dim button As System.Windows.Forms.Button = New System.Windows.Forms.Button()

Private Sub button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click

    End Sub

And I get the error:

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Then I change it to this:

Friend WithEvents button As System.Windows.Forms.Button

Private Sub button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click

    End Sub

And when I run it I get a NullReferenceException

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also the best way to do this is create a separate class Employee.

This may compile and run but you should never do it like this:

public static void setEmpName(String empName) {
   System.out.println(empName); // EXAMPLE
}

The empName is the name of the employee when on the other hand the PayrollProgram1 is the class where you run your program, so they need to be separate. quuba gave you this advise because probably it was the best way to correct this kind of code. And if you take a better look at your code you will see that the way you called that method was completely unnecessary

Here is an example:
1st class:

class Employee {
private String empName=null;
private int hoursWorked = 0;
private int hourlyPay = 0;

public Employee() {

}

public String getEmpName() {
  return empName;
}

public void setEmpName(String empName) {
  this.empName=empName;
}

//generate the rest of the get/set methods

public int getWeeklyPay () {
   return hoursWorked * hourlyPay;
}
import java.util.Scanner; // load scanner

public class PayrollProgram1{ // set public class
    public static void main(String[] args){ // main method begins    
        Scanner input = new Scanner(System.in); // create scanner to get input
       
        Employee empl = new Employee();
        empl.setHourlyPay(10);

        System.out.print("Enter Employee's Name."); // enter employee's name
        empl.setEmpName(input.nextLine());

        System.out.print("Enter hours worked."); // enter hours worked
empl.setHoursWorked(input.nextInt();

        System.out.printf("Employee Name: %s, Weekly Pay is $%d%n", empl.getEmpName(), empls.getWeeklyPay()); // print final line
    }
}

You might think that there isn't much difference but later you will …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Would any one give idea About How to attach scanner through VB6

May I suggest the VB forum

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And what are you trying to accomplish by doing this:

jl1=new JLabel("<html><center><font face=Maiandra GD size=5><u>Welcome to</u><p>School Management System</font></html>");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Not until you show us what effort or analysis you made in tracing that error.
And as I said before do not just vomit back what your system throws back at you, show us some analysis, some effort from your side.

**Also my instinct suggests this is not your code so better show some effort in at least diagnosing the error**

I would like to add something to stephen84s's comments. The error you get is quite clear but you didn't even bother reading it:

Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at Base64.main(Base64.java:35)

There is an error (NullPointerException) at line: 35 in the file: Base64.java inside the method: main

As the error says: at Base64.main(Base64.java:35)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

"Hi this is Satbir Singh doing a job in a insitute as a trainner for c cpp java etc. But i have some appllication programs that is being difficule to solve for me in java . Would somebody plz help me for solving these problems that i m atteching with this messasge.."

Read this link

And then post a specific question

EDIT: Also, now that I looked at the doc, no one is going to complete a 5 page homework, when you have showed nothing on your behalf. Especially when it is kids stuff like declaring classes with properties

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I didn't notice any private constructor in ByteBuffer and I don't there should be any since it is an abstract class. You are not supposed to initialize it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You could have easily found out about this method: split() if you looked at the java API.

You should be always consulting and searching the APIs for something that you might need.

Useful packages:

java.lang
java.util
java.text
javax.swing
java.io

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Who is stopping you from submitting it?

masijade commented: A great starting point. +11
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hello. readers....
i am computer student last year...
i want help from you...that i need some projecy defination which is ni java...please help ...

If you search this forum you will find other posts were people ask for projects and some have project ideas

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From what I understood I presume that each line in the file will have many values (probably comma separated) that need to be put in each row of a 2D array.

If this is the case then when you read the line use the split method of the String class:

String s = "a,b,c,d";
String [] array = a.split(",");

Then the array will have elements:
array[0] = a
array[1] = b
array[2] = c
array[3] = d

Afterward you can take these values and put them wherever you want

puneetkay commented: Thanks for telling abt this method! :D +2
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you say table you mean database table?
If yes do an order by and read the data using ResultSet. Then check for duplicates

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

But I dont need text. I just need to know how to use the sort in the applet

If you want to use it, just call it and sort an array.
But how would you show to the GUI the results? Aren't you supposed to print them somewhere?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Applets are not my strong point.
But I advised you to use a JTextArea and display in each line the elements of the array.
Check the API of JTextArea on how to append and set text

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't say what doesn't work and what errors you get.

Also it would be a good idea to print the values in 1 line:

for (int scan = index+1; scan < numbers.length; scan++){
           if (numbers[scan] < numbers[min])
               min = scan;
           for(int i=0;i<numbers.length;i++) {
			 System.out.print(numbers[i]+", ");
          }
          System.out.println();
         }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you again post the code, the error, and the commands you are using to compile and run

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I run the program and it works ok.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The post at the top of this forum should get you started.

Also I didn't see a question in your post. What do you expect us to do for you?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can create an array with some numbers inside.
>Then print its values,
>Call the sort method
>Print again the values.

Also if you want to see how the sort progresses you can change the methods given and add some :
>System.out.printlns after each loop is run.
Every time a loop of the method is executed print the values. (You will need another for-loop) to print the values.

As for applets have a textarea where you print the values of the array in each line. Check the API for the JTextArea class. Also you probably have some notes on how to create an applet.


What I can't understand is why you where given the code ready and asked to do it in applet. Usually applets are more "advanced" than a simple sort method. How can your teacher expect you to write an applet when you haven't even learned the simple sort algorithms since he is handing them to you ?

I believe that you should first learn how to write these sort algorithms before being asked to do them in applets

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

so would i do something like this:

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter true to repeat game.");
boolean true = keyboard.next();

if this is right would i do this in the while loop or outside of it
thanks for your help

I don't believe that this is correct: boolean true = keyboard.next(); because you can't give your variables names like: true which is a keyword for java.

I was thinking something like:

System.out.println("Enter N to stop game.");
String input = keyboard.next();

if (input.equals("N")) {
  stop = true;
}

But since you have marked the thread solved you probably have already figured it out

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

This forum is full of examples on how to read input from the keyboard.
Do a little search.

Also check the classes:

Scanner
BufferedReader

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
boolean stop = false;

while (!stop) {

//code to be repeated 


//ask user if he/she wants to stop
if yes stop = true;
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all don't put a 'throws' at the main.
Second of all the error is very easy to figure out. Check your notes on how to write and run a simple program.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check this link on how to determine what kind of class is an instance:

http://en.wikibooks.org/wiki/Java_Programming/Keywords/instanceof

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Because when you do this:

String [][] array2D = new String[5][];

You don't create a 2-D array, but an 1-D array that takes as 'elements' arrays. So you can do this:

array2D[0] = new String[2];
array2D[1] = new String[10];
....

and access like:

array2D[0][0];
array2D[0][1];
//array2D[0][2] : this is wrong because the first element of array2D is an array with length 2. So you need to be careful with the for loops

array2D[1][0];
array2D[1][1];
...
array2D[1][9];
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Like I said I have never used them but you could check out the API:

Blob
SerialBlob

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have never used these objects before but I can tell you that you get the exception because you don't instantiate the 'msg' object:

Blob msg; <-- it is null so when you write this:
msg.setBytes(1,msgval) --> you get the exception

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The driver you are using, seems to be correct.

Have you tried this:
Go to Project Properties > Java Build Path > Libraries. and add the mysql connectivity jar ?

Also can you try to add this:
printstacktrace, inside the catch:

public void initDB(String url) {
    		    try {	   
    		      Class.forName(driverName).newInstance();
    		  //  Connection con = DriverManager.getConnection(url);
    		      db = DriverManager.getConnection(url,"******","******");
    		      statement = db.createStatement();
    		     System.err.println("The database in initialized");
    		    } catch (Exception e) {
    		        System.err.println("Unable to find and load driver");
    		       
                        e.printStackTrace();
                         
                        System.exit(1);
    		      }
    		    }
    	}

And tell us what it prints

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One more thing that I forgot to add in the example.
If you want the HTML to create a link like this:

<a href="viewdata.jsp?value1=John">John</a>

The jsp should be:

<a href="viewdata.jsp?value1=<%= rs.getString(1)%>"><%= rs.getString(1)%></a>

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also when you write something outside the <% %> it is displayed the way you write (HTML style).

So when you write this:

<a href="viewdata.jsp?value1="+sth+">"+ . . .

It will not concat. It is not java and it is not a String to concat it.
If you want to display the value of a variable do this:
<%= rs.getString(1)%>
It will put whatever value it has as "part" of the HTML page.
So might want to write this:

<a href="viewdata.jsp?value1=<%= rs.getString(1)%>"><%=rs.getString(1)%></a>

No semicolon inside the <%= %> and notice the: "" of the href, as well as where the <> opens and closes:

<a href= "viewdata.jsp?value1=<%= rs.getString(1)%>" >
<%=rs.getString(1)%>
</a>


Also make sure to read peter_budo's post and follow his advice. My post was just for informative purposes. It is not correct to open database connections inside a jsp, and use the ResultSet that way to create a link

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have attached the file with the sorts. I have to show 2 sorts insertion, and selection sorts demonstration in bars. I should show the position of the bars after each run. How do i go on about doing that?

What do you mean when you say:
I have to show 2 sorts insertion, and selection sorts demonstration in bars.

What is this bars?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also a second example:

class FrameMaster extends JFrame {
  Frame1 frame1;
  Frame2 frame2;

// create somehow the 2 frames
public FrameMaster() {
  frame1 = new Frame1(this);
  frame2 = new Frame2(this);
}


 void openFrame1() {
   this.setVisible(false);
   frame1.setVisible(true);
 }

 void openFrame2() {
   this.setVisible(false);
   frame2.setVisible(true);
 }
}
class Frame1 extends JFrame {
  FrameMaster master;

 public Frame1(FrameMaster master) {
  this.master = master;
  } 

 void openMasterFrame() {
   this.setVisible(false);
   master.setVisible(true);
 }
}

class Frame2 extends JFrame {
  FrameMaster master;

 public Frame2(FrameMaster master) {
  this.master = master;
  } 

 void openMasterFrame() {
   this.setVisible(false);
   master.setVisible(true);
 }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Version1:

class Frame1 extends JFrame {
  
  public Frame1() {
     
  }   

  private void methodClose1_Open2() {
      this.setVisible(false);
      Frame2 frame2 = new Frame2(this);
      frame2.setVisible(true);
  }
}
class Frame2 extends JFrame {
  Frame1 frame1 = null;

  public Frame2(Frame1 frame1) {
      this.frame1 = frame1;
  }   

   private void methodClose2_Open1() {
      this.setVisible(false);
      frame1.setVisisble(true);
  } 
}

Version 1:
As you can see Frame2 does NOT call a constructor. It uses the 'previous' frame that opened it (frame1).
Frame2 takes as argument a Frame1 object so you need to put the existing frame, not create a new:

Frame2 frame2 = new Frame2(this)
frame2.setVisible(true)

OR Version 2 of Frame1:

class Frame1 extends JFrame {
  Frame2 frame2 = null;

  public Frame1() {
     this.frame2 = new Frame2(this);
  }   

  private void methodClose1_Open2() {
      this.setVisible(false);
      frame2.setVisible(true);
  }
}

Again, the Frame1 constructor will be called ONCE therefor the Frame2 will be called ONCE.
Then you just use the instances to change the visibility of the frames

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What exactly are you trying to accomplish?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I got it. Here is the thing. The error you get is this:

Exception in thread "main" java.lang.StackOverflowError

If I remember correctly it usually happens when you run out of memory due some "endless loop" thing. Please someone correct me if I am wrong.

And here is the practical reason why you get an error:

In main you do this: new test0(); You create a new instance of test0. What happens when you do that? : You create a new instance of test1:

test1 t1 = new test1();
public static void main(String args[] ){
new test0()
}

What happens when you create a test1 object? :
You create a test0 object
class test1{
test0 t0 = new test0()
....
}

Then the above code calls the constructor of test0 (a NEW instance of test0) therefor a new test1 is created :
class test0{
test1 t1 = new test1();
....
}

And when you created this test1 another test0 is created, then another test1 is created then another test0 is created, .... then you get that overflow thing.

You created an 'endless loop'.
It was like doing this:

public void method1() {
    System.out.println("method1");
    method2();
}

public void method2() {
    System.out.println("method2");
    method1();
}

Execute the above code and see what happens

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also it is best/common practice to have the attributes start with lower case:

private String achterNaam;

public String getAchterNaam() {
  return achterNaam;
}

public void setAchterNaam(String achterNaam) {
  this.achterNaam = achterNaam;
}

Notice how the case changes from lower case to capital at the get/set method:
achterNaam
getAchterNaam

It was a good think that you overridden the toString() method

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try this: Integer

int is 'smaller' than long so it can fit inside a long. If you write this: double d = 1; wouldn't be correct? But it is like putting an int inside a double. It will 'fit'

Also from the link provided you can find the max integer value that can fit in an int variable: Integer.MAX_VALUE

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

\n is within a string...

String str = request.getParameter("textfieldvalue");

I want to display the value of str to other pages..using this link below.

window.open("page.jsp?param=<%=str%>")

....the problem is that the window is not opening due the str has \n.


How to read \n in a string?

I don't know if it will work, but try to replace the char: '\n' which is in the String with this: <br>

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hello,
Please tell me in Java we don't have a multiple inheritance? so,in which function we use these inheritance.

Thanks

You say:
> we don't have a multiple inheritance
but then you ask:>in which function we use these inheritance

The only thing I can say is that java doesn't have multiple class inheritance, but multiple Interface implementation.

If that doesn't cover you, ask a better question

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And for my insert query, i got a error saying "Number of query values and destination fields are not the same.". What does this mean?

Probably the number of values you are using are not the same with the number of columns you have in your query.
Pay more attention to puneetkay's post.
Also try posting the query you are trying to run

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi all

I have a miniproject I need to submit tomorrow ,but I didn't finish it..

Please if any member have a time to check it for me,,tell me so I can send my whole work...

I really will appreciate your help
Please help me ....Iam so sad its 50% out of score:(

Apparently by the time you read this, you should have delivered your project.

But just for you to know your above pots doesn't make any sense. We are all willing to help, but you didn't ask any questions nor you posted any code.
What were we supossed to relpy to the above post? You said you needed help but where is the project for us to view it and check it?

If it was too big you could described it, ask your question by saying where you are having problem and upload the files of your code.
Just an advice for next time

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
num5 = num1.subtract( num2 );

Also when you create your class and declare the private variables, you will need to implement the methods described.
Example, with the above you will have a public method he take an argument a Complex object.
Inside the method you will use the get methods of object: num2 to get the real and imaginery part, do the subtraction with the real and imaginery part of num1 and with the results create a new Complex object and return it.

I once started to create some sort of library for Complex numbers (for fun) but I got bored. It was designed to handle even calculations like: cosh(Complex x) or arctan(Complex x)

Just have get, set methods for the variables and use your Math book for the calculations.

Also you will need to implement the toString() method:

public String toString() {

}

It is automatically called whenever you do this: System.out.println(num1); or System.out.println("num 3: "+num3);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, you didn't post a question, and second there is a link at the top of the forum created just for you:

http://www.daniweb.com/forums/thread99132.html

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

what would you think of a [9][9][9] array? each row and column would have an array, and so would each cell. After a number is used, you could remove it from the rows and columns, then remove it from the positions within the 3x3 square...

This is the same solution as my first.
Instead of an [9][9][9] array which would mean as you said an array [9][9] with each cell having an array with numbers and after a number is used remove it,
you could have an array [9][9] with a Vector in each cell. I thought it would be better because how do you intend to remove a number from an array?
If you had a Vector you could use the remove() method which removes the element and reduces the size of the Vector.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I had an idea once of how to do this but I didn't like it very much.
Here is what I have thought:

Each cell (81 cells) will be represented by a Vector (perhaps an array [9][9] of Vectors). Each Vector will have numbers from 1 to 9.
Suppose you want to decide what number to put at cell (i,j). You will take the values of that Vector and randomly pick one of those numbers. Once you have selected the number, You will remove that number from ALL the Vectors that are at the same row, column and square.
So when you want to decide what to put at cell (i,j+1), the Vector will have 1 less number since you removed from it the value you placed at (i,j), so again you will randomly choose a number from the existing values and you will remove that from the rest of Vectors.
In the end all the values will be removed except from one, the chosen one.

Like I said, as an initial thought it's not very smart (an array with 81 Vectors isn't very efficient).

Another thought is having a Vector with the available numbers for each row, column and square (27 Vectors) and whenever you place a number at the cell (i,j) you will remove that number from the available numbers of the specific row,column and square. Of course when you select a number for (i,j) you will need to check if …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes, but that still doesn't guarantee that value will == 0, unless you explicitly set it to be so.

In your code you say:

static class GameButton extends JButton{
   int value = 0;
}

So why value wouldn't be zero?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't want to sound ignorant, or pretend that I know everything, but does this code make any sense to you all?
Because if the purpose of the code is reading a specific file then I don't think this is the right way.

What exactly are you trying to accomplish?
What is it that it doesn't work?
What do you get and what do you expect?

jasimp commented: You mean you don't know everything ;) +9
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hi Friend,

am providing good project for u in java....it cost of US Dollar 300 and am having more student project in java...and IEEE... for the IEEE project am providing US Dollar 350...


Regads,

Venkat

This is a java forum for experienced developers to help others to learn and understand.
You think that we are stupid or incapable of writing CORRECT code and selling it?