Not everything on the internet is true!!!
If that is the case then I'm not sure I should believe you!
Not everything on the internet is true!!!
If that is the case then I'm not sure I should believe you!
Where do all these lies about TV and the Internet come from?
Well, uh, hmm.... the internet...
:P
An example of converting text field inputs to ints
JTextField txtField = new JTextField();
String textValue = txtField.getText();
int value = 0; // starting with a default of 0
try {
value = Integer.parseInt(textValue);
} catch (NumberFormatException nfe){
// you can either leave it zero or tell the user it's not a good value
// or whatever you need to do if the text can't be parsed to long.
System.out.println("bad value");
}
System.out.println("value="+value);
Read the api doc on Integer.parseInt(). It indicates that it will throw a NumberFormatException if it cannot convert the string to an inv value. Your program needs to handle this. You can't perform math on nulls or empty strings, so it's up to you to decide what to do if that text can't be converted to an int.
That was merely an example of coverting a string, which you get from the text field, into an int value. You need to pass in your own string variable.
You can create an HTML table, but if you are wanting an interactive JTable you'll need to place that as a separate component.
waa.. i dont know understand about public String getText()...
can you give me a sample of it??this is my action for the PRINT button:
public void actionPerformed (ActionEvent e) { if(e.getActionCommand()=="PRINT") { String temp=""; temp=rice1.getText(); output.append(temp); rice1.setText(""); }
not working though :(
That's because your button says "Print", not "PRINT". Your check on the action command is failing because of that.
Another way to determine which component is making the call is to use e.getSource() and compare that to your components
public void actionPerformed (ActionEvent e)
{
if(e.getSource() == print)
{ String temp="";
temp=rice1.getText();
output.append(temp);
rice1.setText("");
}
Well, "...." doesn't give much insight into what you are doing with your lists, but to perform math operations on the elements you will need to cast them to Integer types. If you are using Java 1.5 or 1.6, auto-boxing will let you add them directly. Otherwise you will need to use Integer.intValue() to convert the Integer objects to int primaries and then add them.
If you first run the text through an expression that separates the uncommented code sections from the commented out sections, you can then parse only the uncommented sections.
I understand what you are saying now. I just needed it explained differently, I'm a bit of an idiot.
Bah. My first comment was pretty brief, so asking for clarification is far from being an idiot. Glad you got it :)
Sorry, I don't understand what you're saying.
I'm saying that your incrementing methods are changing the state of your Time instance. All you need to do after you change that state is to display the new Time
System.out.println( "Time before incrementMinute method" );
System.out.printf( " %s\n", t2.toString() );
t2.incrementMinute()
System.out.println( "Time after incrementMinute method" );
System.out.printf( " %s\n", t2.toString() );
The logic to manage the state of your Time instance has nothing to do with displaying it. You already have a method for the display, so you just need to call it.
You could have made the increment methods return a formatted string that was ready to display, but then you would be mixing what really should be separate responsibilities: managing state and viewing it. Keeping those two separate, as they are now, keeps your design more flexible.
There is no need for a mthod to retain it's own state separate from it's instance context. If you need to maintain state in an object, make it a class level variable. If you really feel that the method MUST retain it's own separate state then you probably have a case for a separate class instead of a method.
The incrementing methods don't necessarily need a return value. Just call the increment method and then show the new time toString().
Your set method may also need to throw an IllegalArgumentException when an our of bounds parameter is passed, like 61 minutes. Also, 60 minutes is actually 0 minutes and hour++. :)
Perhaps it may be too late into your assignment to consider this, but do you really need to keep two separate lists that only vary by sort order. As you are finding with your current task, having multiple copies of the data means that all operations on that data must be kept in sync. If you later want to be able to sort by genre, you are forced to add another list and more methods to support that list. You can see how such a design becomes more difficult to deal with as it grows.
I think you would be better off keeping a single list and providing methods to resort it as needed.
Is there a requirement that you implement your own linked list and not use a built in collection such as ArrayList? Collections.sort() provides an easy mechanism for sorting based upon any Comparator that you wish to use. Also the collection classes that are part of the Java Collections Framework are already fully featured and tested. It looks like your current remove(int index) still has a bug where it does not update the "next" reference after deletion here
Node curr=prev.getNext();
I know that is a lot of potential change to throw at you after you have gotten this far, but you would have an easier time managing a single ArrayList collection in the long run.
You are correct that "this" refers to the current object instance. YWhen you add a listener the parameter is typed to an interface. You can supply an object which implements that interface. The interface merely guarantees that certain methods are available on that object. Here your gui class implements the listener interfaces itself and therefore is a valid listener. You do not need the "insGui" variable at all in your case.
You could use the following for the countdown
class ButtonCountdown implements ActionListener {
int count=0;
JButton button = null;
public ButtonCountdown(final JButton button, int count){
this.count = count;
this.button = button;
}
public void actionPerformed(ActionEvent e) {
if (count>0){
button.setText(String.valueOf(--count));
} else {
button.setText("Done!");
}
}
}
and then start it like so after you have the UI all set up
Timer koTimer = new Timer(1000, new ButtonCountdown(ko, 5));
koTimer.start();
You need to set up a Swing Timer to handle the countdown on the button. See the following on timers:How to Use Timers.
The behavior you are getting right now is because you are sleeping in the thread that is creating the UI. Create the UI first and after it is set visible, start the Timer task that updates the label on the button (and it's behavior if needed).
You don't need to "implement" that class then. You just need to declare an object of that type and use whatever methods you need on it.
Well, is the "other classname" an interface? The declaration expects you to have an interface name there, which your class implements. When you say "call " an external class, what exactly are you trying to do?
You have no guaranteed return statement in doMath(). If op falls through all of the cases in your switch, the method would not return a value. Add a default return value after the switch and it will be fine
static int doMath(char op,int numa, int numb){
switch (op)
{
case '+':
return numa + numb;
case '-':
return numa - numb;
case '*':
return numa * numb;
case '/':
return numa / numb;
}
return 0; // or another default if you prefer
}
Ah, never mind, it is not the Console method. On that line you are calling
cc.setAcctTypeCode(Console.in.readInt());
but you haven't initialized "cc" yet. You can't call methods on objects that are not yet created.
I think the problem is most likely with your Console.in.readInt() method. Are you sure this Console class is working correctly? Why not simply use Scanner for reading the values?
Does anyone have time to look over a 3 class program? I get a NULL POINTER ERROR. What is the best way to debug a variable that produces this error? Thanks
Yes, as mentioned, the stack trace should tell you which method the error occurred in and the line number.
You can also use "if" checks and System.out.println() to verify variables if you are having trouble locating the problem:
String s = null;
if (s==null)
System.out.println("a is null here!");
or you can use assertions
String s=null;
assert s!=null : "s is null!";
To use assertions, you must run the program with the "-ea" flag to enable them (ie "java -ea MyClass"). If the condition of the assertion is false, it will stop the program with an assertion error and show the message that you have supplied.
You really don't need to cancel execution of the method, just don't perform any other actions after the display of the message. It looks like your current method will do that just fine as it is. Just remove the System.exit() call.
You just need to declare them at class level. You can initialize in the constructor as shown or in whichever method reads the first question. Subsequent calls to get the next question just use the same scanner.
class MCQquestion extends JFrame implements ActionListener
{
private static final int WIDTH=550;
private static final int HEIGHT=200;
private static final int HLOC=340;
private static final int VLOC=290;
private JPanel pnlQ, pnlA,pnlButton;
private JLabel lblQuestion;
private JFormattedTextField txtAnswer;
private JButton btnNext;
//Not Sure what u meant... Im totally new to Java..
//but declaring it here, at class level generate 'unreported Exception' during compilation
//where do i insert throw IOException
//Try n catch dint work at class level..."invalid declaration.."
File questionFile = [B]null[/B];
Scanner questionInput = [B]null[/B];
public MCQquestion()
{
[B]try {[/B]
[B] questionFile = new File ("question.txt");
questionInput = new Scanner (questionFile).useDelimiter("//");
} catch (Exception e){
// deal with exceptions here
}
[/B]
lblQuestion = new JLabel();
try{
MaskFormatter ans = new MaskFormatter("U");
txtAnswer = new JFormattedTextField(ans);
txtAnswer.setPreferredSize(new Dimension(40,30));
}
catch(ParseException pe)
{
System.out.println("Error: " + pe.getMessage());
}
.... the code continues...
Declare the scanner at the class level and do not re-open it in the listener. Let it use the one you have already opened.
Do you mean JAVASWING for 2D Graphics?
Well, your graph would be on a JPanel, but you would override paintComponent() with your own code to generate the shapes, lines, etc. Here again is the link to the tutorial on 2D graphics: http://java.sun.com/docs/books/tutorial/2d/index.html
I will give you a website address:
Could you kindly have a look, my idea is most probably like this
http://www.pms.ifi.lmu.de/software/jack/docu/doc/VCHR-Manual.html#sec:Using
Ah, yes for that you will have to use the Graphics2D api to draw your graphs. There isn't any standard component for things like that. As for the constraints, you need to design classes for those based upon whatever optimization methodology you are employing. The tutorial link for 2D Graphics should get you started with the visual part.
Yes, really you just need to run queries on the database for any records that conflict with the constraints. Those records can then just be shown in a table or list. For that matter, the entire schedule could be shown in a table with conflict cells higlighted by color or something.
Not sure if you are storing the ID as a number or a string in the db, but if it is a number then drop the single quotes in the where clause. Other than that the SQL look just fine.
You just need to save the class in a file called PayrollApp.java. It works just fine. I'm assuming your file name does not match the class name.
Only if they must be stored as strings. If you provided sample input and output and indicated what you need to do with the output, it would be helpful in answering the question.
If it is only a matter of displaying them with leading zeros to the user then there are several formatting methods availble for that (i.e. String. format , Formatter , DecimalFormat )
Example:
int x = 123;
int y = 23;
DecimalFormat df = new DecimalFormat("0000");
System.out.println(df.format(x));
System.out.println(df.format(y));
Erm maybe because 08765 isn't an integer?
Exactly. If you really need leading zeros then you have to create that String representation yourself - which will undo the whole point of converting in the first place.
hi everyone
i have a very a very basic question in mind .. i wanted to discuss ..Difference Between these?
String s1= new String("java") ;
String s2="java" ;
Strings are immutable in Java and the String class maintains a pool of String objects that have been created. Using a String literal, as with s2 above, the String class will return the reference of the existing String, so all references to equivalent String literals will point to the same String object. When you create the String with the new String("java")
constructor, you will actually get a new copy of the String "java", not the reference from the String pool. The following fragment of code will demonstrate this
String a = "java";
String b = new String("java");
String c = "java";
System.out.println("a==b : "+(a==b)); // false
System.out.println("a.equals(b) : "+(a.equals(b))); // true
System.out.println("a==c : "+(a==c)); //true
what for 2 different classes are there in garbage collection?
System.gc and runtime.gc ( both are doing the same job)
what is their individual role?please anyone explain me....
They are effectively the same. This is stated in the API documentation for the two methods.
The call System.gc() is effectively equivalent to the call:
Runtime.getRuntime().gc()The method System.gc() is the conventional and convenient means of invoking this method.
Ok, I think I know what is causing your issue. Check your db.conf file for the root_path property. If you left it set to the default 'jvm' then you need to change that to use "configuration" as below
# root_path - If this is set to 'jvm' then the root
# path of all database files is the root path of the
# JVM (Java virtual machine) running the database
# engine. If this property is set to 'configuration'
# or if it is not present then the root path is the
# path of this configuration file.
# This property is useful if you are deploying a
# database and need this configuration file to be the
# root of the directory tree of the database files.
root_path=configuration
#root_path=jvm
Well, your question barely makes sense given the code that you posted (which needs code tags too). Maybe this example of writing to a file will help http://www.exampledepot.com/egs/java.io/WriteToFile.html
You need to reset index and tmp before scanning each line. Also you don't have any checks on index vs strLine.length() so if you did have a line with no spaces in it you will get an index out of range.
Actually swing is the base of Java graphic, because when you work on swing you have to cover all the fundamentals. So it is good to start.
By yourself working, it will take little more time to do your work successfully.
I understand the connection you are making, but one can make UIs with Swing without having to directly use any of the Graphics or Graphics2D methods. Only when he gets into wanting to produce charts and graphs would he need to learn the Graphics2D API.
That is the reason that I mentioned them separately. They can be treated as two independent subjects basically.
I think you want to increment "countChar "instead of "count" in this statement
if(Character.isWhitespace(NB.charAt(i)))
{
++count;
}
:)
Hi
I am looking on Graphics JAVA API. Where i can create an UI and interact with it, kind of Graphs, Charts etc.,
The graphs and charts can be done with the 2D Graphics api. The tutorial posted above by eranga262154 is a good start to working on that.
The UI itself involves using the Swing packages. Tutorials on using Swing can be found here: http://java.sun.com/docs/books/tutorial/uiswing/index.html.
HI
Iam ready to do this project. Please send your requirement to this email id : <email address removed>Regards
Deepak Xavier
This thread is not seeking someone to complete this work. It is merely discussing some technical questions that the original poster has. Please do not hijack threads offering to solve them for pay. This is not the forum for that.
java -cp ./mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo is the command I used. How can the same command produce syntax error on computer and work on the other?
My computer must be possesed. I will try a different computer and post back.
You can actually do away with the "./" altogether and just use "mckoi1.0.3/mckoidb.jar", but really I can't see any reason why the command would be balking and printing the usage.
Hrmm, not sure what the trouble there is then. I recreated that exact path situation(for the jar) and a copy of your class and ran it here with no problems.
javac -cp./mckoi1.0.3/mckoidb.jar ./EmbeddedDatabaseDemo.java
Compiles fine. But
java -cp /mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo
is not working. It prints out the java usage file as
if my synatax were incorrect. Can you see what I am
doing wrong?
Try java -cp ./mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo
I think you need the "." in front of the path entry if you are referring to a relative folder. I assume you have the jar in a folder /mckoi under whatever directory your class is in?
Your connection code works just fine for me. I believe you still don't have the class path quite right. You said you used -cp with the javac command, but what about when you run it with the java command? Try
java -cp /mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo
You may have to alter that classpath to match your jar location if I inferred it incorrectly.
Ah, ok, sorry I misunderstood you. Class path is all you need to specify to tell your app where to find those files. Class path is merely a list of locations to look for classes that it needs to import. If those are not in the default Java jar files, you need to specify them with either a %CLASSPATH% environment variable, via the -cp switch on the command line, or by listing them in the Class-Path entry in the jar manifest file.
More info on class path can be found here:
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
I'm realy interested how this work also. Never did it before....
Would you mind Ezzaral to elaborate on the question? How exactly you point your application toward this JAR file?
If you are asking about the executable jar file, the jar file is the application. In Windows you can just double-click it to run (not sure how other OS handle that) or you can run it with java -jar MyApp.jar
.
The main class of the application is specified in the jar manifest file by a property called Main-Class. This is the class that contains the main() method to execute when the app is run.
The classpath for other dependencies outside of your own jar file, such as third-party jar file libraries your app needs, is specified by the Class-Path entry in the manifest.
The manifest allows you to specify pretty much all of the info Java needs to run your program with the exception of command line options. Those you would still need to set in a batch file or shortcut to execute the program.
You can package up the entire app directory stucture in a single zip file such as the following
/MyApp.jar
/RunMyApp.bat (if you need to set switches on the java command)
/config.xml
/images/(any image resources here if you need them)
/lib/(other jar files your app depends on like JDBC dirvers,etc)
More info here if you need it:
http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
Yes, there are other ways to deploy your app. See the following:
http://java.sun.com/docs/books/tutorial/deployment/index.html
In particular, I would recommend an executable jar file.
A lib folder is nothing more than a folder named "lib" in your application root directory where third-party libraries are placed. It's just a common convention.
You will have to distribute the database jar file with your app. It can simply reside in a /lib folder. You definitely do not need to add it to the JDK folder.
As far as the classpath, it is not uncommon at all to have a batch program that sets the desired classpath prior to launching the program. If you are distributing your app as an executable jar file, the files in your lib folder can be added to the Class-Path property in your manifest.mf file. If that is done, you won't even need to set the classpath prior to execution.
"visualization java tools"? Do you mean the graphics APIs? Please describe what you are wanting to do a little bit more.