In Work Calculator [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to do a calculator which just i need a multiplication . I will gave a example. Imagine 2 jTextField. I need to get data which is wrote to these jtextfields, and multiplicate them. And show result and jTextField3. This work needs the work under Action Performend jButton. It can be easy for you guys but i didnt understand. Thanks for reading..
num1=Integer.parseInt(txtfield1.getText());
num2=Integer.parseInt(txtfield2.getText());
total=num1*num2;
totalField.setText(String.valueOf(total));
Note:I tried this code but it didnt work. But i need just like that.
I just need a new code entire code about what did i said on the question . Ok i'm nut giving order to you but , just please help me. Or what should i do ?

2 problems with the code that we can see:
NumberFormatException isn't caught
Ints are not declared
Use this instead:
try{
int num1=Integer.parseInt(txtfield1.getText());
int num2=Integer.parseInt(txtfield2.getText());
int total=num1*num2;
totalField.setText(Integer.toString(total));
} catch(NumberFormatException e) {
totalField.setText("Error in input");
}

Related

Printing statements using a method [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Basically I've been set some work where I have to have 4 methods but I don't really understand how methods work. One of these methods basically has to print out two set statements that's it and I have no idea how to do it as most examples across the web deal with methods being used for maths and nothing as simple as printing out two lines for a title. Can anyone please help?
Method is just a way of extracting a piece of code and making it callable on demand. So if you print out two lines...
System.out.println("This is line 1");
System.out.println("This is line 2");
And you want to call it more than once, then you would extract it into a method.
private void myNewMethod()
{
System.out.println("This is line 1");
System.out.println("This is line 2");
}
Then call that method from anywhere in your program like so
myNewMethod();
These types of questions are off topic however as you need to demonstrate an understanding of your problem before we can help fix it.

I need user input to puts a date where the tokens (/) are automatically put in [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Sorry in advance if this was already answered but what i need is for an user to input a date in this format AAAA/MM/DD. But when the user puts the year (4 numbers) the token(/) automatically appears not giving the user user the option to put it himself.
And the next question is how do i make the user only to input numbers without thinking in the before checks.
This in advance
Try MaskFormatter:
MaskFormatter formatter = new MaskFormatter("####/##/##");
JFormattedTextField textField = new JFormattedTextField(formatter);
'#' stands for only number input
I think you cannot do that at least in a multiplatform standard.
More info here but I don't think it will help. http://docs.oracle.com/javase/6/docs/api/java/io/Console.html
Maybe there are JNI multiplatform consoles somewhere that support it.

Value of the String [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have just come across a string variable in my application code where the value is assigned as follows
String YEAR="${year}";
What does the value of the String variable here?
Without being interpolated, just ${year}.
I can almost guarantee that String is going to be interpolated elsewhere in the code.
Maven, for example, uses this syntax to inject variable values into it's configuration settings.
Use an IDE such as IntelliJ and do a find usage on this variable. An extended find (search/find in path) may also yield results.
As others here have suggested, It is most likely being interpolated somewhere else.

is there any way to read from text file word by word (i.e without using split)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
is there any way to read from text file word by word (i.e without using split)? . I am able to read line by line directly with nextLine() with a scanner object, but I got error when I tried with next(). Thanks in advance.

user Input Date in the form 01-Jun-2013 and output be 6 i.e., current day of week, using java i.e., swings [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
for example:
Monday-1,
tuesday-2,
wednesday-3,
thursday-4,
friday-5,
saturday-6,
sunday-7,
if my input is 01-Jun-2013 then my output should be 6,
if my input is 02-Jun-2013 then my output should be 7,
if my input is 03-Jun-2013 then my output should be 1,
I need code in java(swings).This is my requirement, I tried in many ways but i'm getting only 7 Calendar.DAY_OF_WEEK.
Thanks in advance.
I will point you in a direction, but you have to do the work since everyone else seems to think you are a student trying to get us to do your homework. Visit this site and check out the Calendar class. http://docs.oracle.com/javase/6/docs/api/
Date is also another good Class to know.

Categories

Resources