211 Posted Topics

Member Avatar for aditya027

Yes. In super class you may define a method to invoke the method of the subclass so that you may call the method with the super class reference. [CODE]class Superclass{ void display(){ System.out.println("Super"); } void Sub2Display(){ // the extra method you define to call the method of its subclass Sub2 …

Member Avatar for aditya027
0
114
Member Avatar for surk23

The following code may help you: [CODE]import javax.swing.*; import java.awt.event.*; import java.awt.*; public class MultiButtons extends JFrame implements ActionListener{ JButton btn[] = new JButton[3]; // define and allocate for the array of 3 buttons String colorName[]={"RED","BLUE","GREEN"}; // the string on each button Color color[] = {Color.red, Color.blue, Color.green}; // Color …

Member Avatar for tong1
0
1K
Member Avatar for runee1000

I put your two java files into a folder with an image "dot.jpg". I have successfully compiled the MyApplet.java. Only one deformed image is shown in both ways: appletviewer and a browser. Check your image file name, your image file extension and other technical problems. It works in my folder.

Member Avatar for MTSranger
0
104
Member Avatar for neo_31591

The constructor as indicated in API: JButton(String text, Icon icon) 创建一个带初始文本和图标的按钮。 There fore your code line: b2=new JButton("Back"); // b2 is a JButton with ImageIcon? should be replaced with b2=new JButton("Back",back);// back if the instance of ImageIcon

Member Avatar for tong1
0
114
Member Avatar for Mirage'

Mirage, (1) NormR1 wants you to know that JOptionPane is a class rather than a package. In your program you use JOptionPane which is in the package : javax.swing. Therefore your import statement should be either: import javax.swing.*: or import javax.swing.JOptionPane; (2) You have no need to use an input …

Member Avatar for Mirage'
0
234
Member Avatar for gauravk_bhanot

The following code may help you where clicking mouse may relocate the label. [CODE]import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MovingLabel extends JFrame{ int x,y; // define the location of a label JLabel label; // movable label Container container; MovingLabel(){ super("Test a movable label"); x=y=100; label= new JLabel("label relocated"); …

Member Avatar for gauravk_bhanot
0
3K
Member Avatar for nocookies92

(1) The buttons show up in my machine (JDK 1.6). So it seems to be some problem with your machine. You may use Button of AWT rather than JButton of swing which is a lightweight component and does not show up among any AWT stuff. However, your case is OK. …

Member Avatar for new_programmer
0
2K
Member Avatar for jemz

You may do in the following way. Assume the word you are going to random has n characters. In the original character order of the word, each time you select one as the first letter and print it. And then print the rest of the letter (with their order) so …

Member Avatar for jemz
0
1K
Member Avatar for ben1

jon is right. You have to put the printLoop method into the main method. This means when interpreting the program (executing the main() method only) the printLoop() is called. However, there are two ways to follow jon's instruction. (1) you have to place a keyword static before the method printLoop(), …

Member Avatar for ben1
0
130
Member Avatar for har58

har58, you should make plan beforehand. For example, (1) pre-store 20 existing random nmbers in an array. (2) when executing program store the distinct 5 random numbers in another array one by one. Should we start with the following code as clues: [CODE] public class RandomNumSelected{ int random[] = new …

Member Avatar for tong1
0
175
Member Avatar for java_programmer

Do you mean you try to get another windonw ? Did you use javaw on DOS? If so there would be no console available so that no printed output on screen. But how do you know the System.console() returns null? [URL="http://developer.51cto.com/art/200907/135170.htm"]The standard method to use console() method[/URL] (starting from 1.6)is …

Member Avatar for NormR1
0
971
Member Avatar for AlexN

NormR1 is making a sense. May I ask you why you use Scanner in Applet? As far as I understand the Scanner is used for DOS window input. If it is a web application, you may have to create a Textfield instance to receive data a client inputs.

Member Avatar for tong1
0
240
Member Avatar for glamourhits

Replace line 40 by the following code: [CODE]name=JOptionPane.showInputDialog("Enter Student's full Name:\nClick Cancel to terminate program"); if (name==null) { JOptionPane.showMessageDialog(null,"Bey for now.","Welcome to DANIWEB", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }[/CODE] This is to set up a guard so that if client clicks cancel button, the program may terminate. Replace your main method with the …

Member Avatar for glamourhits
0
218
Member Avatar for Greece

Start with Java tutorial on the Internet, e.g. [URL="http://download-llnw.oracle.com/javase/tutorial/"]http://download-llnw.oracle.com/javase/tutorial/[/URL] Some text books, such as [URL="http://www.deitel.com/"]Java How to program [/URL]by H.M. Deitel, P.J.Deitel is also good.

Member Avatar for Greece
0
97
Member Avatar for jemz

In line 3 you should define a String instance pal instead of String array. Therefore you have to modified the following code related to the pal. The instance "console" is created by the constructor Scanner, so the lines 10-18 should be replace by one line: Scanner console = new Scanner(System.in); …

Member Avatar for jemz
0
387
Member Avatar for pptech

I guess you did not follow NormR1's instruction precisely. I have tested your program. It works. [CODE]import javax.swing.*; import java.awt.*; import java.awt.event.*; class simo2 extends JFrame implements ActionListener{ private JRadioButton red; private JRadioButton yellow; private JRadioButton blue; private JRadioButton green; private JRadioButton magenta; Container container; public simo2() { super("Radio Button …

Member Avatar for tong1
0
7K
Member Avatar for gauravk_bhanot

After one minute you add the second component which is the new ball with the x coordinate of 300. Then you should immediately ask the JFrame to re-arrange the layout via the following code: [B][COLOR="red"]frame.validate();[/COLOR][/B] Therefore, you should insert the line of code into line 84 (shortly after the catch(Exception …

Member Avatar for tong1
0
312
Member Avatar for tong1

I am interested in Current threads, such as : rare program :s [url]http://www.daniweb.com/forums/thread300723.html[/url] how to create 2D array of enumeration values [url]http://www.daniweb.com/forums/thread300738.html[/url] which have a common goal: to store the names of Enums objects in a 2D array of String. For example, we have a pack of porker cards defined …

Member Avatar for ~s.o.s~
0
2K
Member Avatar for Xufyan

I wonder if the following way is a candidate answer for Xufyan's question? Should we make Days type 1D array and Periods type 1D array to play a go-between role? Then use the method name() to store the names in two final String arrays? [CODE]public class Enumeration0 { enum Days …

Member Avatar for tong1
0
6K
Member Avatar for zombieman023

[URL="http://www.cs.princeton.edu/introcs/13flow/"]http://www.cs.princeton.edu/introcs/13flow/[/URL]

Member Avatar for tong1
0
36
Member Avatar for Xufyan

It could be: int arrey[][]= {{1,2,3},{4,5,6},{7,8,9}}; May I suggest you write a method : void printArray(int a[][]); like the following code by red color to print any 2-D array. When you create a two-demension ladder form in opposite way, some of the minor changes should be made. The following code …

Member Avatar for tong1
0
123
Member Avatar for kdgeiger
Member Avatar for Xufyan

Yes, To replace "--k" with "k=k-10" is a proper way to do so. The --k is only for the purpose of one decrement. The '--' is an unary operator. There is no other unary operator for the purpose of , such as two- or three- decrement. You have to use …

Member Avatar for Xufyan
0
117
Member Avatar for therstonsplace
Member Avatar for priyanka.js28

Java has no destructor. If you want to dereference an object of DERIVED class, you may assign a null to the reference of the object so that calling the System.gc() will return the corresponding space to the OS sometime later. The garbage collector soon or later will collect it no …

Member Avatar for JamesCherrill
0
149
Member Avatar for walter307

In line 1 the condiction for while loop answer.equalsIgnoreCase("Y") repeats once. Why?

Member Avatar for new_programmer
0
142
Member Avatar for Baadal

As I understand, we may use JDBC to do the job for MS Access. Java provides SQL(including updating) methods.

Member Avatar for Baadal
0
1K
Member Avatar for JAN811

JDBC and MS Access is a good choice as you indicated. In addition to sports, may I mention about some other topics. Depending on the data source available, and your own interests, you may work on a database for a particular research field. For example for a research on political …

Member Avatar for tong1
0
75
Member Avatar for walter307

Your program can not be compiled successfully. Where is your declaration for average,jgrade... the code in line 26 is a dead loop if (average < 101) The last curly brace is redundant that should be removed.

Member Avatar for walter307
0
176
Member Avatar for hazeeel

See the [URL="http://www.daniweb.com/forums/thread294844.html"]thread: http://www.daniweb.com/forums/thread294844.html[/URL] which may help you.

Member Avatar for jon.kiparsky
0
623
Member Avatar for NewOrder

Should we delete the break; in the line 29 since the default: valid=false; [U][COLOR="Red"]break;[/COLOR][/U] is the last case.

Member Avatar for NewOrder
0
120
Member Avatar for jjhames

Should we start with one bubble sort? Can you explain why 1. the usefulness of the boolean flag "change" ? 2. why the upper limit of the embedded loop ( “ for(j=0;j<i;++j) ” )is i rather than n? You may figure out the descending sort and other sorting methods, such …

Member Avatar for jjhames
0
735
Member Avatar for NewOrder

java.io Class Console is wonderful since it lets you to access the character-based console device, if any, associated with the current Java virtual machine. [COLOR="red"]Console console=System.console();[/COLOR] However, the java.util Class Scanner is also goog since it may carry the same job. [COLOR="Red"]Scanner in = new Scanner(System.in);[/COLOR] I have two comments. …

Member Avatar for tong1
0
214
Member Avatar for shahreza

My way to fufill the staticstics task is implemented via different arrays. The final result is represented via a two dimension array. The column fields are indicated by different rooms while the rows name by different indexs. The final result is shown via the 2-D array: indD/BARU|A005|A002|A001|BSK 2/3|A106/107|B202|B208/209|A 101|A 118|A …

Member Avatar for shahreza
0
123
Member Avatar for kulrik

On Nov. 7th VernonDozier has clearly and correctly indicated the steps in writing a code to calculate. Please following the instruction write your own program.

Member Avatar for tong1
0
237
Member Avatar for coroll

May I point out the following errors after glancing at your code. 1. javax.servlet is included in J2EE platform rather than J2SE. There for the package does not exist on our J2SE platform. 2. any local variables in a method should not have accessing modifier. Only the data members, that …

Member Avatar for coroll
0
340
Member Avatar for tong1

Assuming that I have text in JTextArea where the characters are presented in different Font and colors since the class has a method :setFont(Font f), setForeground(Color fg). I wonder if there is a way to save it on MS Word.

Member Avatar for tong1
0
86
Member Avatar for tong1

The following project is considered appropriate for a graduation dissertation in Computer Science Graduation project if the supervising professor is good in Java An English Word Statistics in Java The function may include: 1. To ask client to select a text file to open (FileDialog would be good to start …

Member Avatar for peter_budo
0
589
Member Avatar for tong1

Palindrome is a popular title for programming training. You may compare a pair of chars in a string, or a pair of words in a String array. Many homeworks are made in this way. Further more, in Java we may play with all the speaking languages in the world, such …

Member Avatar for tong1
0
158
Member Avatar for 0xCMD

You did not show line 28 as error message indicates. Your result will be always 1 since int division: 1/(e*i) always 0. You should declare double e = 1.0 instead of int e; For example, the java method in calculating PI using Lord formula could be: [CODE]double Lord(int n) { …

Member Avatar for tong1
0
95
Member Avatar for jemimaloh

The following code may (1) extract the coordinate values in the 3 float columns in the file "data.txt" under the same folder, and (2) print the extracted float data only on DOS window. [CODE]import java.io.*; import java.util.*; public class CoorToks { public static StringBuffer buffer; public static BufferedReader input; public …

Member Avatar for jemimaloh
0
2K
Member Avatar for TechLover95

You should establish your own Java developing environment at first to test your code step by step. I have almostly always used the text book [URL="http://www.deitel.com/"]"Java How to program" [/URL]by H.M.Deitel, P.J.Deitel for years.

Member Avatar for peter_budo
0
129
Member Avatar for dylgod

[code] /* “PositiveInt.java” receives an integer greater than 0. In this program Exceptions are catched accordingly */ import javax.swing.*; public class PositiveInt{ static class NonNegativeException extends Exception{ public NonNegativeException(String msg){ super(msg); } } static void show(int x)throws NonNegativeException { if (x<0) throw new NonNegativeException("Negative integer is not valid."); } public …

Member Avatar for tong1
0
141
Member Avatar for dylgod

// I have corrected your program as follows: import javax.swing.*; public class speedofsound { public static void main(String[] args) { String input; int medium = 0; medium = Integer.parseInt( JOptionPane.showInputDialog(null, "Enter 1, 2 or 3 \nPick a medium : 1 for Air, 2 for Water and 3 for Steel")); switch …

Member Avatar for tong1
0
112
Member Avatar for student.09

The error message shows: (1) in line 9 you call a non-existing constructor of 2 arguments. As your teacher requests, you should define "a constructor that creates a rectangle with the specified width and height" only. You did not do so. Instead you have defined a constructor with 3 arguments:width,height, …

Member Avatar for tong1
0
184
Member Avatar for rowley4

The nested loop can be written as follows: [CODE]import java.lang.*; public class NumberPrinted{ public static void main(String args[]){ int n = Integer.parseInt(args[0]); int number = 10; for (int i = 0; i< n; i++){ for (int j=0; j<10; j++) System.out.printf("%4d", number++); System.out.println(); } } } [/CODE] Using C-style "printf("%4d", a)" …

Member Avatar for rowley4
0
74
Member Avatar for Xufyan

/* Could be written in the following way */ [CODE]public class divisible { public static void main(String args[]) { int[] divisible; int toTal=0; divisible = new int[] {4,9,25,144}; System.out.println("The elements divisible by 5 are printed as follows:"); for (int i=0; i<divisible.length; i++) if (divisible[i]%5== 0){ toTal++; System.out.print(divisible[i] + " "); …

Member Avatar for tong1
0
97
Member Avatar for khRiztin:)

You may down load the Java Applet program Scribble.java [URL="http://www.partow.net/projects/jpaintbrush/index.html"]http://www.partow.net/projects/jpaintbrush/index.html[/URL] It works. It is pointed out at the web site: Free use of the Java Paint Brush is permitted under the guidelines and in accordance with the most current version of the "Common Public License."

Member Avatar for khRiztin:)
0
786
Member Avatar for matwe

Java Applet has a security rule: To open,read,write a file in client computer is not allowed. This is a security measure. Java security issue can be found in the following web site: [URL="http://groups.csail.mit.edu/mac/users/jbank/javapaper/javapaper.html"]http://groups.csail.mit.edu/mac/users/jbank/javapaper/javapaper.html[/URL]

Member Avatar for tong1
0
88
Member Avatar for usiyalla

1. Robert W. Sevesta (2002, Concepts of programming languages, 5th edition, page 107 ) pointed out that “ a token of a language is a category of its lexemes.” “Formal descriptions of the syntax of programming languages, for simplicity’s sake, often do not include descriptions of the lowest-level syntactic units. …

Member Avatar for NormR1
0
1K

The End.