Actionlistener For Calculator / Button Are Created Within A For Loop For Number 1 To 9
Mar 8, 2014
coding the action listener for my button (btBody) which create button displaying 1 to 9 in a nested for loop; the button should allow the user to click on them and to display the number clicked on in a JTextField;my code;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class EX_7_2 extends JFrame
{
public EX_7_2()
{
setLayout(new BorderLayout(5, 10));
[code]....
View Replies
ADVERTISEMENT
Dec 19, 2014
So I am working on an ABV calculator for some practice, and one problem I am running into is that I am unable to set a JLabel properly on the top of the window that is created. It will display the text with no problem, but only on one column. Is there a way to center a JLabel across 2 columns? The label I am working with is titleL.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class Beer_Calculator extends JFrame
[Code] .....
View Replies
View Related
Nov 28, 2014
Is there something special about this? I would think not, however all of the buttons in my application work except those with images.Here's an example of one:
Java Code: // Class #1
// All components defined as private initially, used in initComponents() later to build GUI
private JButton btnRock = new JButton();
/** Create the frame. **/
public GameView() {
initComponents(); // Initialize components
} // End of GameView Method
public void initComponents() {
// ROCK BUTTON
btnRock = (JButton) mainController.createIcon("rock");
btnRock.setForeground(new Color(0, 0, 0));
btnRock.setBounds(12, 34, 97, 67);
[code]....
View Replies
View Related
Jul 13, 2014
So I have this issue with ActionListener, I have created JMenuItems in a loop and applied them to JMenu's. But now when I want to make an action listener for each button, I'm not sure how to select them individually as in the loop it's 1 object looped through different names.
Here is the way I made the menu.
package com.simbaorka101.te.gui;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import com.simbaorka101.te.reference.Reference;
public class Menu extends JMenuBar{
private static final long serialVersionUID = 3601135828398064405L;
[Code] ....
View Replies
View Related
Mar 7, 2014
Can I add actionListener to a button component without creating a reference to it? Look at my code below:
public void init() {
setBackground(Color.red);
//Create the layout
setLayout(new BorderLayout(20, 5));
//Add buttons
add("North", new Button("Red"));
add("South", new Button("Yellow"));
add("East", new Button("Cyan"));
add("West", new Button("Magenta"));
add("Center", new Button("White"));
}
Or should I just do the usual instance.addActionListener(this) like myButton.addActionListener(this)?
View Replies
View Related
Mar 31, 2014
I want to make a game and I have the following:
A main JFrame which include some text and a Button (The Start Button), and I made an ActionListener for that Button to another ActionListener which have a for, but when I run the project I only see the final of the for loop.
View Replies
View Related
Feb 15, 2015
cm2yOUa.jpg
Write a piece of code that would change something in the one of the buttons created using the loop? I have spent few hours reading about the arrays, different methods and can't think or apply a working solution.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class C2loops extends JFrame implements ActionListener {
private JButton jBTile, jBClicker;
private JPanel jPLeft, jPRight;
[Code] ....
View Replies
View Related
Mar 13, 2014
Which is the best way to keep track of the number of the objects I've created?Is is a good practice to have a static variable, which will be incremented everytime I call a contructor?
Class circle{
private double x,y,radius;
private static count;
Circle(double x1, double y1, double radius1){
x=x1;y=y1;radius=radius1;
count++;
}
View Replies
View Related
Mar 11, 2015
import javax.swing.*;
public class BasicCalculator{
public static void main (String[] args) {
String output="";
double n1,n2;
String operation;
operation= JOptionPane.showInputDialog("Please enter your operation");
[Code] ....
How to add a loop in this problem:
View Replies
View Related
Dec 2, 2014
I have the basic workings of this program just doing all the printing at the end is throwing me off. Anyway here are some of the requirements and my code:
1. Allow the user to input an individual's hours worked.
2. Accumulate the total regular hours worked, the overtime hours worked, the amount of the regular pay, the amount of overtime pay, and the total payroll, for all of the employees entered.
3. Allow the user to enter a zero (0) as the Boolean expression to end the loop.
4. When the loop ends print out all of the accumulated totals with appropriate labels, each on a separate line.
import java.util.Scanner;
public class WhileLoopPayCalc
{
public static void main(String [] args)
{
final double REGULAR_HOURS = 40f;
final double HOURLY_WAGE = 12.5f;
final double OVERTIME = 1.5f;
[code]....
View Replies
View Related
Mar 30, 2014
I need to design the layout of this calculator and also add one more button that clears textbox strings one by one instead of whole.
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.*;
public class Calculator extends JFrame{
double value1;
double value2;
String operator;
double result;
[Code] .....
View Replies
View Related
Oct 12, 2014
I just started Java a few days ago and I'm having trouble with ActionListener..
Here are my codes so far , i'm having trouble with the
btnDetermineAction10686696_842067395825457_2521361553839739125_n.jpg:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NumberAnalyzer extends JFrame{
private JButton btnDetermine, btnClear;
private JTextField txtNumber, txtFactors, txtPrime;
private JLabel lblNumber, lblFactors, lblPrime;
private JPanel pnlNumber, pnlNumber1,
[Code] ....
The output should be the one in the picture:
Input is placed at the NUMBER text field.
Identify its factors, write it at FACTORS text field.
Determine if it is prime. If prime, output at PRIME text field is “Yes”, “No” otherwise.
View Replies
View Related
Jan 30, 2014
I am trying to restrict the number of views in JSF 2.0.2 using
<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>5</param-value>
</context-param>
In my case my managed bean is View Scoped and it supports a UI page which has multiple forms and each form is submitted as AJAX POST request.
As per the statndard, setting restriction to 5 should create 5 views and after that based on LRU algorithm the oldest views should get deleted if 6th views is created.
Therefore any action on the oldest view will throw the ViewExpiredException and i simply redirect the user to view expired page.
1) When i set the restriction to 5 views, i open 4 tabs with 3 forms each.
2) I submit the 3 forms on first tab everything works fine.
3) As soon as I go to 2nd tab and submit the first form thr, i get view expired exception
4) It seems I am exceeding the number of views I mentioned in web.xml
I want to know :
1) Does every AJAX POST submit itself creates a view ?
2) How I can count the number of views created in a session ?
3)Can i force expiry of a view in JSF 2.0.2 while the session is still alive ?
4) Normally JSF 2.0.2 session cachces the views. Lets assume session is alive the entire day but a view was created in morning at 9:00 AM and is not used again the entire day. Assuming that session doesn't reaches the max number of views it can save in entire day, will the view created in morning expire on its own after certain interval of time ? If not , can we still force its expiry while keeping the session alive ?
View Replies
View Related
Nov 13, 2014
I need to do a simple while loop pay calculator. I am very new and not sure what I need to do to put all the requirements in the new code from another code. Here is my code that doesn't work yet.
1.Place the wage calculation routines in a while loop.
2.Allow the user to input an individual's hours worked.
3.Accumulate the total regular hours worked, the overtime hours worked, the amount of the regular pay, the amount of overtime pay, and the total payroll, for all of the employees entered.
4.Allow the user to enter a zero (0) as the Boolean expression to end the loop.
5.When the loop ends print out all of the accumulated totals with appropriate labels, each on a separate line.
import java.util.Scanner;
public class WhileLoopPayCalc
{
public static void main(String [] args) {
final double REGULAR_HOURS = 40f;
final double HOURLY_WAGE = 12.5f;
final double OVERTIME = 1.5f;
double wage = 0f;
[Code] ....
View Replies
View Related
Feb 1, 2015
the program basically has a random number generating, and I want to ask the user to try to guess the number, and keep guessing until the number is right. In addition to this, I need to put in extra conditions for too high or too low by 10. So for example, if they user guesses a number and its off by more than 10, then it prints that they guessed too high, and if its below 10 they guessed too low.
import java.util.*;
public class RandomNum
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
[code].....
Modify the program to keep the user trying to guess the number till he/she gets it right, and stop once you guess the right number.Too high, high, too low, too low( If it's off by more than 10 = way too high, if its less than 10, way too low)
View Replies
View Related
Jun 10, 2014
end the loop with the ESC button.
import java.util.Scanner;
class Sum {
public static void main(String[] args) {
int sum = 0;
System.out.println("Please write a number, end with ESC button");
Scanner in = new Scanner(System.in);
[Code] ....
View Replies
View Related
Jun 10, 2014
I'm doing old projects . This loop will take any number, sum it and when you press the ESC button the loop will end and you will be shown the sum.
Java Code:
import java.util.Scanner;
class Sum {
public static void main(String[] args) {
int sum = 0;
System.out.println("Please write a number, end with ESC button");
Scanner in = new Scanner(System.in);
int number = in.nextInt();
[Code] ....
Here is the error
Java Code:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The operator != is undefined for the argument type(s) int, null mh_sh_highlight_all('java');
So well, the int ain't boolean says itself. also null ain't that for string ?
The original project was to get the number using one dialog box, convert the string to int and run the loop, so when you pressed ESC there then the return would be null.
View Replies
View Related
Nov 9, 2014
I'm back with a question about the Black Jack assignment. I've created a working game that works for one round, as well as a reset button that's able to clear the board of the old hand. However the runGame() loop, which checks whether a player has played his hand seems to freeze the program the second time around
private void initNewGame(){
dealer.addCard();
for(int i = 0; i < numberofplayers; i++){
players[i].addCard(); //draws card, adds score and paints card to the board
players[i].setStatus(false); //makes the buttons usable in the players[] class
[Code] .....
I know it's probably not optimal having an while loop constantly running to check the status, but I can't seem to figure out why it freezes.
View Replies
View Related
Feb 9, 2015
Everything is working great except for my back button at line 172. It works good but if I try to click the "insert" button again. It gives me the java.lang.NumberFormatException error. Other than that it works fine, the "insert" button still works.
package userDatabasePack;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Database{
//Variables
private String username2, insertUser, insertPassword;
private int insertUserId;
[Code] ....
View Replies
View Related
Feb 10, 2014
a. Write a code that is written inside a body of a method named average that takes two parameters: N that determines number of terms you should calculate the average of and lowBound that is the beginning term of the geometric sequence. if lowBound is 4 and N is 3, then the average of 4, 8, 16 is calculated and returned.
My code runs fine if I set the test as 16, but I can't figure out what I could do to N to have it determine the number of terms. This is what I have so far...
public class AvgIt {
public static void main (String[]args) {
double result = average(4, 3);
System.out.println("Average is " + result);
[code]....
View Replies
View Related
Jan 29, 2014
int[] a = new int[7];
a[0] = 0;
a[1] = 10;
a[2] = 256;
a[3] = 57;
a[4] = 33;
a[5] = -154;
a[6] = 168;
[code]....
What program needs to find is the most biggest number. It does the job, but another task of the program is to find the index of that number . The second loop should do just that, but for some reason, as the loop goes further, it passes through the if statement even though answer "a[i]" is not equal to "answer". The idea is that if a[i] and answer are equal, the "i" should represent the index number.
View Replies
View Related
Sep 15, 2014
What I am trying to do here is allow input to loop until 0 is entered for the product number. When 0 is entered, it should then dump the total for each individual product. I've tried it about a dozen different ways and have yet to be able to get the loop to function as intended. The way I have the code below, the loop will not function at all (where as before it looped, but never finished).
import java.util.Scanner;
public class Sales {
public static void main(String[] args) {
double total1=0.0;
double total2=0.0;
double total3=0.0;
double total4=0.0;
double total5=0.0;
int product;
[Code] ......
View Replies
View Related
Jun 3, 2014
What's wrong with my code. It says 'you win' even when I guess an incorrect number. And then the 'win' message keeps repeating. I'm thinking I need a way to generate a new input? And then maybe take the 'win' message out of the loop, but that breaks it too.
View Replies
View Related
Jul 8, 2014
I have a problem with my application. It supposed to store 4 different Room objects but when I entered one only it stores tat object variables into all my Array elements. I just need it to store any number of objects as long as it is less than 4.
Java Code:
import java.util.Arrays;
import java.util.Scanner;
import javax.swing.JOptionPane;
class TestRoom {
public static void main(String [] args)
{
String[] roomsInHouse = new String[4];
[Code] .....
View Replies
View Related
Mar 23, 2015
import java.util.Scanner;
public class AvgLrgSml{
public static void main(String[]args){
System.out.print("Hello there. Please enter any three numbers.");
Scanner keyboard = new Scanner(System.in);
double num1 = keyboard.nextDouble();
double num2 = keyboard.nextDouble();
[Code]...
View Replies
View Related
Jun 28, 2014
I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.
What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:
class factorial {
public static void main( String[] args) {
Scanner scan = new Scanner(System.in );
int num;
int product = 1;
[Code] ....
View Replies
View Related