Graphical Program With Several Label Objects - How To Use Infinite Loops

Feb 22, 2015

I'm writing a graphical program with several Label objects. One of them is supposed to constantly change color. I tried to do it with while loop like this:

while (true) {label1.setColor(Color.blue); pause (80); label1.setColor(Color.red); pause (80);}

However, the rest of the code (after the loop) is never reached because the loop never ends. Is it possible to use infinite loop like this? And, is there any other way to handle permanent processes that are supposed to run as long as the program is running (like, in this case, blinking Label)?

View Replies


ADVERTISEMENT

Unable To Clear All Graphical Objects Of A Type Trees

Oct 20, 2014

I am trying to clear all graphical objects of a certain type(all trees in particular). I have never had any issues doing so, and this method normally works well along with these variables:

Java Code:

public static ArrayList<GRect> historyT;
public static ArrayList<GOval> historyL;
public static GRect trunk;
public static GOval leave;
public void deleteTrees() {
//clears all tree trunks and leaves

[Code]...

That is this normally worked until I started added more trees to the screen after they had all been erased. What happens is that it won't clear all of them unless the max has been reached, that is 6. It will remove all trees up till the last one if the max has not been reached. In other words here is my screen before the clear all if the max has not been reached(* is a tree, _ is erased): ****

Here is it after: _ _ _ _ *

So my question is, is why aren't all the trees deleted? Why does it leave one left behind?

View Replies View Related

Putting ImageIcon Into Label (Original Size) By Clicking On Label (Thumbnail Created Before)

Nov 6, 2014

I'm doing a software Java GUI - JFrame form like this:

1. The user wants to click on a button that opens a bunch of images that will be displayed as thumbnail in the bottom of the JFrame .
2. Then the user wants to select/click one of the thumbnail and make appear the corresponding image in it's original size on above(center) of the JFrame.

For doing this I used 3 JPanel.

One contains a JButton that opens the jfilechoser dialog window,
the second "panelPreview" is for putting the thumbnails created,
and the third "panelGrande" is for the image in it's original size.

The firs part "1." is ok.

But in the second part : I got one error when I want to put the ImageIcon in to the JLabel with the further intent of displaying it.

lblBig(imgIcoVett[i]);

In this project I'm dealing with arrays of ImageIcons and JLabels, so it's a bit advanced level for me, so I'm not sure that I wrote right the part of the MouseListener too.

The error displayed by netbeans says "cannot find symbol symbol: method lbl (ImageIcon) local variables referenced from an inner class must be final or effectively final"

Here I attach the project I did with netbeans"AAAD Unlayout 2.zip", but if you just need the highlight of the code, here it is too:
 
private javax.swing.JButton btnOpenfile;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lblBig;
private javax.swing.JPanel panelGrande;
private javax.swing.JPanel panelPreview;

[Code] ....

View Replies View Related

Get Text From TextField To A Label But Label Is On Different Frame

Nov 18, 2014

I need a code to get a text from a textField to a label but the label is on a different frame, i will give u an example of what i have so far. so this is the main:

package albaestate;
public class AlbaEstate {
public static void main(String[] args) {
Frame1 first = new Frame1();
first.setVisible(true);
}

/*[B]now i have the first frame where i input the information[/B]*/
 
package albaestate;
public class Frame1 extends javax.swing.JFrame { 
public Frame1() {
initComponents();

[Code] ....

What i need is to input the code so that in jLabel5 i get the text from jTextField1 in Frame1; in jLabel6 i need the text from jTextField2 also in Frame1; and in jLabel7 i want to display the calculation of what the jbutton1 in Frame1 is calculating.

View Replies View Related

Unable To Set Text To A Label Multiple Times In Same Program

Aug 5, 2014

I am developing a java swing application. In which i want to set a different text to a label in same program ( in single JFrame). I dont want to use another JFrame instead i want to use setText method of java and set different text to a label at different intervals of time according to my need.

I am using java 1.7 sdk and pupy linux as OS. Below i am giving source code.

What i am doing is in constructor of class i am setting an image to JFrame and setting text "Welcom...". And when user clicks on this JFrame a method is called which will clear the text "Welcome.." and sets new text to another label "Enter...." and from there another method is called and it clears label "Enter..." and sets a text "Plzz wait..". and yet there are more methods, i havnt provided here.

But what is happening is it shows welcome text and then directly Plzz wait..

Its not showing text Enter... because control is finished after last method gets executed.

My concern is i want to show all the setText (my messages) in a sequence. Without using another JFrame. There is no any user input other than user will click on first welcome page.

public class BackgroundFrame extends javax.swing.JFrame {

JLabel setTitle1;
JLabel setTitle2;
JLabel setTitle3;
JLabel setTitle4;

[Code] ....

View Replies View Related

Program That Shows A Square Frame Filled With 100 Buttons Label

Apr 13, 2014

Write a program that shows a square frame filled with 100 buttons labeled 1 to 100. Nothing needs to happen when you press any of the buttons. I keep getting errors i am a beginner.

import java.awt.Frame;
import javax.swing.JButton;
import javax.swing.JPanel;
class TestFrame extends Frame {

[Code] ...

View Replies View Related

Lottery Odds Program - Using For And While Loops With Calculations

Oct 13, 2014

/**
* In this program, use for and while loops with calculations to get the lottery odds.
*/
import java.util.Scanner;
import java.util.Random;
public class Lottery
{
public static void main (String []args)

[Code] .....

I need getting my numbers matching. When, I run the program each time no matter what number it keeps saying sorry no matches. However, I do need the program to have matches.

View Replies View Related

Infinite For Loop

Oct 13, 2014

I wrote a program that asks the user for their letter code to tell them where they are supposed to go. I was then told to comment out asking the user and to use a loop to print each possible destination. I decided to use a for loop and am stuck in an infinite loop.

//Sam Kluender
//MajorDestination.java
import java.util.Scanner;
public class MajorDestination
{
public static void main(String[] args)
{
char major;
int countLang, countGifford;
Scanner reader = new Scanner(System.in);

[code]....

View Replies View Related

Display GUI By Using Graphical Nodes?

Feb 8, 2014

I need to calculate id=hash(number) xor id.id is string and number is random number.

My problem is how to convert my string ex='hello' into equivalent integer,so that i can do xor.

I have client and server program. I need to display a gui by using graphical nodes.

View Replies View Related

Infinite Loop Error

Apr 18, 2014

I just started my first programming class and I'm already playing catch up. It's a hybrid and the lectures are really short and fast paced that I don't entirely understand what is going on. I also got my textbook late (I was on the waitlist so didn't want to commit to buying early), so it's been a rough couple weeks.

Basically, I'm supposed to simulate a rental service transaction where the user will input numbers 1-4 to indicate which equipment they want to rent and input either H/h or F/f to indicate if it's for a (H)alf-day or (F)ull-day. I think I'm getting stuck in an infinite loop because every time I enter run the program to test the conditions in the loop, the console returns the "invalid choice" statement that I created in case the user inputs numbers less < 1 or > 4.

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner;
public class Rental {

[code]....

View Replies View Related

Graphical User Interface

Apr 26, 2015

I am making an app that would allow user to buy seat either by Price or Choice (Row and Column). I have Original code where it runs within JAVA IDE I am making same thing but rather in GUI now. I need putting my Buttons, textfield, and area in organize fashion.

I have not explain how these buttons will behave or act but right now putting them in order is priority then I will add action listeners to do the task we intend to do. A Wire Frame of the code looks like this :

Here is NON GUI Code:

import java.util.*;
public class HW06
{
static int[][] seats =new int[][] {
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 20, 20, 20, 20, 20, 20, 10, 10},
{10, 10, 20, 20, 20, 20, 20, 20, 10, 10},
{10, 10, 20, 20, 20, 20, 20, 20, 10, 10},
{20, 20, 30, 30, 40, 40, 30, 30, 20, 20},
{20, 30, 30, 40, 50, 50, 40, 30, 30, 20},
{30, 40, 50, 50, 50, 50, 50, 50, 40, 30}
};

static int rowSize, colSize;
static String strChoice;
static Boolean finished=false;
public static void main (String[] args)

[Code] .....

View Replies View Related

How To Stop Infinite Loop Programmatically

Mar 24, 2015

I am developing application called java compiler... It takes java program as input and compiles and run it, gives output. but if input program has infinite loop then how can identify and stop process execution.

View Replies View Related

Java-8 :: How To Stop Infinite Stream

May 26, 2014

I have a Stream instace which produces values using an infinite Supplier (it supplies values taken from an electronic sensor -- so unless the battery is low, the sensor will provide "for ever").

The stream is processed by a Collector using Stream.collect() (e. g. imagine that the values from the sensor should be averaged; in fact what it does is a bit more compliacted maths).

The problem is that the collector does not produce a result but hangs up, as the supplier does never stop providing more sensor values.

So what I need is a limitation rule that stops the stream. While there is a Stream.limit(long) method, it actually does not solve my problem as in my case it is not practical to stop after a particular count, while I actually want to stop streaming when the sensor value exceeds a particular limit etc. (hence, voids an arbitrary rule).
 
To sum up, what I need is Stream.limit(Predicate), i. e. the stream will stopped once the predicate becomes true.
 
Unfortunately I did not find anything like that in JRE 8.
 
Is that planned for JRE 8.1 or JRE 9.0? Or is there a known (and sophisticated) workaround?

View Replies View Related

Java Application For Infinite Series That Calculates PI

Sep 5, 2014

I am having trouble compiling my code for a java application that is supposed to print out the infinite series for Pi. Here is my java code:

//a java application that generates the infinite series for Pi, ie 3.14159...=4-4/3+4/5-4/7+4/9
 
public class Pi{
public static void main(String args[]){
//declare and initialize variables
 long counter=1;
double pi;
 
[Code] ....

Here is the error in my output that results when I attempt to compile my code:

C:UsersanonymousDesktopchapter five exercises for javaPi.java:21: error: variable pi might not have been initialized
total=total+pi;
^
1 error
Tool completed with exit code 1

Why do I need to initialized pi when I already initialized the total?

View Replies View Related

Infinite Loop On Double Linked List

Sep 11, 2014

I've been stuck for the last couple hours trying to understand why the "printInReverse" method is getting into an infinite loop. I was supposed to make a double linked list that you can insert numbers and it orders both ascending and descending; in this case, descending is the "printInReverse" method, which takes the already ordered lists and prints it reversed, like if it was descending, and that's where the problem lives. Here follows the whole code:

import java.util.Scanner;
public class MyList {
private Scanner userInput;
private Integer selectedOption;
private MyListElement firstElement = null;
private boolean exitRequested = false;
 
[Code] .....

View Replies View Related

Swing/AWT/SWT :: Graphical Front End For A Poker Game?

Oct 19, 2014

basically I'm a good way through developing a Poker game which I've been developing just for fun(!?) and also to improve my skills, which it has done substantially. The logic involved with some of the hand comparisons and the evaluations of the winner is pretty complex.

Nonetheless, once I've finished the threaded timer to control the regulation of rising blind levels, and the betting mechanics for the Computer players I'll be looking to start creating the front end and this is where I'm a little confused.

Obviously for what I want, neither swing or AWT would be sufficient, so I guess the gap in my knowledge is how to integrate my back end code with a web front end. Is this possible? - What options exist for integration? just pure CSS / JS, or would Angular.js be viable? I'm looking to utilise some ready made images as graphics with maybe some minor animation effects.

View Replies View Related

How To Grab Graphical Object From Arraylist And Modify It

Oct 26, 2014

I am trying to grab a graphical object from an arraylist, and reposition its coordinates on a Jframe when adding it. My program of course deals with strings, and once it sees specific words in my console, some method is called that adds, removes, or otherwises modifies certain objects on screen.

Here I want to say something like move(object[1],xpos,ypos) which will move a certain object from a specified point in the array, and move it to new x and y positions on the JFrame. I use a different class that extends a graphics program, so when I say add(something,x,y) it draws the object onscreen where I want it. These are some relevant, though incomplete, methods that should move an object already painted on screen:

Console class

Java Code:

public void doMoveCommand(String cmd, String arg, String xpos, String ypos) {
int x = Integer.parseInt(xpos);
int y = Integer.parseInt(ypos);
if (cmd.equals("posMake") && arg.equals("star")) {
box.moveStar(box.historyG.get(1), x, y); //historyG is an arraylist of GPolygons
freeCommand();

[Code] ....

When I say makepos(whatever) I am getting a arraylist out of bounds exception. How I might be able to accomplish moving objects already on screen?

View Replies View Related

Would Switching References Change Their Graphical Position?

Jan 19, 2014

So I have an array of objects, each with their own position, I tried switch the references in the array of two objects, then repainted (immediately), but the two objects aren't switching positions on screen...does this even work?

View Replies View Related

Swing/AWT/SWT :: Create A Basic Graphical User Interface For Sequence Translation

Mar 3, 2015

I am trying to create a basic graphical user interface for sequence translation (including a JTextField for the description of a sequence and status of function button pressed e.g. “simple” translation and input and output TextFields). This involves a number of different class files. I cannot get my user interface to do what I want and I think I have problems with my "actionPerformed" method. How the code should be linked together?

public void actionPerformed(ActionEvent event) {
try {
// Get the description, content and result
String d = tool.getDescription();
String input = tool.getInputText();
Stringr = translation.getResult();

[code]....

View Replies View Related

How To Remove Objects In Graphics Program

Jul 9, 2014

How to remove multiple objects that are onscreen in a java graphics program(specifically the one from the acm library). The clearAll works fine but I would like to keep the background in my frame. I just want to be able to do something like removing all the trees by typing in a phase into a console program. Here is a small snippet of code with details of what I am trying to achieve.

Java Code:

public void command(){
Dictionary dic=new Dictionary();
//dic list of all phases that will either make animations or remove things in a graphical window
String line = readLine("Type here: ");
if (line.equals(dic.clearActions[i])) {
cleared=true;

[Code] ....

View Replies View Related

Recursive Program - Choose K Objects Out Of N

Apr 20, 2015

I recently wrote a simple recursive program that chooses K objects out of N (I was asked to use the variables N choose the R, however) total objects. Here is the code:

int n = 0;
int r = 0;
//the total number of objects defaults to 0
String nChoice = JOptionPane.showInputDialog(null, "How many objects are there to choose from?");
String rChoice = JOptionPane.showInputDialog(null, "How many object are to be chosen from this group?");
try {
n = Integer.parseInt(nChoice);

[Code] ....

It works fine, however in my class we were given two different formula to implement into our code. I used the one above, obviously. However, the second formula we were given was:

C(n,R) = n!
-------(R!(n-R)!)

I had to get the spacing right.

How do I read this formula? How could it be implemented? What are the benefits (if there are any) from using one method over the other? Which method of calculating N choose K (or, in my case, N choose R) would be more widely accepted?

View Replies View Related

Program Like Applet - Creating Multithreading Or Drawing Objects

Aug 20, 2014

What is the best choice to program like an applet i mean easy with creating multithreading or drawing objects etc.

View Replies View Related

Program That Displays Information For Employee Objects Of Different Types

Apr 29, 2014

I'm making a program that displays information for "employee" objects of different types. This works with a hierarchy that goes Person→ Employee→ Fulltime/Adjunct, and a driver that tests the inheritance. The Person class is given and only supplies the name, the employee class manages the year hired and the ID, and the types of employee classes manage the salaries.

One object (called staff[2]) is supposed to first be printed with default information and then later updated via set methods. I figured out how to update the name, but I don't know how to update the rest of the information because the employee's name is managed in the Person class and the reset of the information is managed in the less-general classes, and the objects are all in an array of Person.

How do I call the set methods necessary to update more of staff[2]?Output (scroll to see the updating section)

The current year is 2012

Name: Flintstone, Fred
ID Num: BR-1
Year Hired: 2005
Years Of Service: 7
Salary: 65000.12
Fulltime Type Employee

[code]....

View Replies View Related

Player One Type A Number And Player Two Suppose To Guess - Infinite Looping

Apr 2, 2014

Its a basic program that is played by 2 people. Player one is suppose to type a number and the second player is suppose to guess the number. However after I test it out, and if I guess too low or too high I get stuck in "Your guess is too low, try again." infinite loop, what is wrong.

import java.io.*;
class GuessingGame
{
public static void main (String[] args) throws IOException
{
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
String firstPlayer, secondPlayer;
int firstInput, secondInput;
int guessCount = 0;

[Code] .....

View Replies View Related

How To Put A Label

Dec 12, 2014

I can't seem to put a label on this code:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class number2 extends Frame {
int x = 0;
int y = 0;
public void run() {
addMouseListener(new mymouselistener());

[code]....

how would I put a label on it?

View Replies View Related

Unable To Add Label To GUI

Apr 17, 2014

I am trying to add a label to my gui, i am using the following code but it is not showing.

contentPane = this.getContentPane();
contentPane.setBackground(Color.GREEN);
contentPane.setLayout(null);
JLabel greeting = new JLabel("hello");
greeting.setFont(new Font("SansSerif", Font.PLAIN, 18));
contentPane.add(greeting);
greeting.setVisible(true);

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved