Changing JButton Text Outside Of GUI Class

Jun 6, 2014

So, Once again I'm attempting to make a Who Wants to Be a Millionaire GUI game. This is the actual game screen code

package WWTBAM;
import java.awt.BorderLayout;
public class GUIGame extends JFrame implements ActionListener {
public static int moves = 0;
public static boolean finished = false;
public static boolean correct = true;

[Code] ....

When ever try and change the buttons text outside of the actual GUIGame constructor i can't. Like in the main method or the action listener.

The code won't work if you copy paste because it's a part of a larger package.

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Changing Text Of JLabel From Another Class

May 26, 2014

Create a dnd (dungeons and dragons) character creator and back ground generator, have it display and run on a gui, to start with i decided to creator the gui as i go so i can see the progress, first i tried eclipse and windows builder, well after 1 day of reinstalling windows builder in about 5 different ways from multiple guides and sometimes getting it to partly work ...

After doing some more research I have figured out how to get the main program to display the gui . Heres what i have:

package com.mrgreaper;
import javax.swing.*;
public class MainWindow {
private JPanel mainWindow;
private JLabel playerlbl;
private JLabel playerNamelbl;

[Code] .....

Now this works fine and the gui displays when the program is run but I can't change the text of any of the jlabels or textfield. If I try to do it in the main class i need to change them from private to public static but then in the form builder it says "cannot bind to static field *name of field*" but if i take static off then i cant change its value!

From what i understand this is because the window is an instance, so how to i change the value in that instance? I could put all my code in the one class, the one that creates the gui, but i really want it seperate, i would like the gui to update as the code runs... So how do i do it, how do i change the contents of jlabels on the fly, read the contents of text boxes on the fly etc....

I tried adding a getter setter

public void setCharFirst(JLabel charFirst) {
this.charFirst = charFirst;
}
in the MainWindow.class

Then i tried to set it from my main function

MainWindow.setCharFirst("test");

but it cant access it as my main function is static and it is not now can i make it static...

View Replies View Related

Changing Of Font When Pressing JButton

Feb 14, 2014

I am having some troubles with a program fileviewer where you must be able to change font style and size when pressing JButton "Set font". I have solved the most of the program and every menu button is working but I don't know how to set in FileListener class method to change the font when running in main class. Anyway, this is my FileListener class

Java Code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.awt.Font;
public class FileListener implements ActionListener

[code]....

View Replies View Related

Set JLabel Text After JButton Press

May 12, 2015

I have four buttons with different names and depending on which button is pressed I want to change the label to be displayed. Center is the name of the label the other directions are buttons. The label should change if a different button is pressed. The error I get is that it cannot be converted to String.

public void actionPerformed(ActionEvent event){
Object source = event.getSource();
if (source == east){
center.setText(east);
}
if (source == west){
center.setText(west);

[code]...

View Replies View Related

How To Change JLabel Text By Clicking On JButton

Feb 25, 2015

Here's my coding so far...I want to be able to change what the JLabel says when clicking on one of the buttons for example : when clicking on UP i want it to say "Going Up!"...how do i do this?

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
 public class BorderLayoutJFrame extends JFrame {

[Code] .......

View Replies View Related

Changing JLabel Text From Anywhere In Program

Feb 18, 2014

I'm using NetBeans.

I have a JFrame with four JPanels, SensorLL, SensorLC, SensorCR and SensorRR. They are instances of the class SensorUI. Each has a JLabel called Sensor.

The class SensorUI has a method writeSensor that writes to the JLabel "Sensor". I will have four temperature sensors. I have not started the code to read the temperature sensors yet. I will have a timer that will run once a second. When it fires I will read the sensors and display the result in the

JLabel "Sensor" in each jPanel.

I use MyMain to call FrameDemo and create the JFrame and a method

in FrameDemo to add the JPanels using addObject.

I can use SensorLL.writeSensor will write text to JLabel Sensor while in Mymain.

Then I start the timer ReadSensor.

When it times out it calls SampleSensors

For an experiment, while in SampleSensors I try to write to the JLabel in the instance SensorLL with

SensorLL.writeSensor("xx_");

I can't because it says it can't find the symbol variable SensorLL in SampleSensors class.

How can I "get to" that JLabel text when ever I need to?

Java Code:

public class MyMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//SensorUI SensorLL = null;
System.out.println("Start of main");
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
FrameDemo.createAndShowGUI();

[Code] .......

View Replies View Related

Swing/AWT/SWT :: How To Change JLable Text By Pressing JButton

Feb 25, 2015

i just started java and I'm trying to change the JLabel text by clicking on the JButton however it isn't working,

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
public class BorderLayoutJFrame extends JFrame
{
public static final int WIDTH = 400;
public static final int HEIGHT = 400;

[Code]...

View Replies View Related

Changing Text Colour Within Quotation Marks?

May 7, 2013

I'm new to Java, & am using Eclipse Helios. How do I change the text colour within the Quotation marks "Try Again" to red, or any other colour, so when I run it, it will display the new colour.

println("Try Again!!");

View Replies View Related

Swing/AWT/SWT :: Changing Text Of JLabel By Pressing A Button?

Sep 20, 2014

I don't get what I missed in the code. I used the example of changing the text of a button by clicking on it, but instead I also added a JLabel and tried to make the button change its text instead, but it didn't work. What did I do wrong?

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class Buttone implements ActionListener{
JLabel label;
JButton button;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Making JButton That Switches Text From 2 JTextFields On Click With Mouse

Aug 6, 2014

I have made a window using JFrame and on my JPanel I have added 3 components: 2 JTextFields ("field1" and "field2") and inbetween them a JButton ("switch"). My goal is to switch the value of field1 to field2 and vice versa when the JButton is clicked. I thought this ActionListener which I have added to my JButton would achieve my goal:

public void actionPerformed(ActionEvent e) {
field2.setText(field1.getText());
field1.setText(field2.getText());
}

However, it changes the value of field2 into the value of field1 but not the other way around.

View Replies View Related

Java Code - Changing Text Size In Windows Settings

Apr 14, 2014

I have a major problem. the text size is like 6 or 8 pt font and I can't read it. I'm trying to run a downloaded exe program which uses the jre7 which I had to download beforehand. the font size stays at 6 or 8 even if I try to change it in windows settings. it's a high res monitor on a lenovo yoga laptop. is there a way for me to edit the java code and manually change the font size?

View Replies View Related

Adding A JButton From One Class To Another

Apr 25, 2014

I'm just learning JFrame and the like, I have 3 classes. I have one class that just calls the methods from the other 2 classes (my superclass), I have one class that draws a frame and adds a panel and then I have my 3rd class, where I'm trying to add a button from in the class to my panel in the other class. However it won't add the button. I'm sure I'm making some obvious mistake, as I'm quite new to Java, but I've been messing around with it for ages and I can't fix it. I'm also not sure if Frame should be extending Test or not.

import javax.swing.*;
import java.awt.*;
public class Test
{
JPanel panel;
JButton button1;

[code]...

View Replies View Related

How To Know JButton Is Clicked In Another Class

May 26, 2015

I have two classes one is called main.java another is called Gui.java

in gui.java, will create a JFrame and some component.here is some code in main.java.

Java Code:

public static void main(String[] args){
while(true)//will always loop once user close the window
Gui gui = new Gui();
gui.setVisible();
if()//at here need to determine button in Gui.java is press or not to process the user input
{
String fromUser = gui.Jusertxt.getText();
}

} mh_sh_highlight_all('java');

what is the code need to use to know Button in Gui.java is clicked or not? i try use method to return true value, but in not working.

View Replies View Related

Changing Ints From Another Class

Jun 27, 2014

I am making a simple text based game and i have a monster, and I am tring to make its health go down whent he user input "s" but istead it doesnt change and the users health even goes up.

Main.java

package exodus.game.main;
import java.util.Scanner;
import exodus.game.monsters.Nirav;
public class Main {
static String name;
static String inputtemp;

[Code] .....

View Replies View Related

Changing File Name To Name Of The Class

Jul 10, 2014

I am starting to learn java , If suppose we write a simple hello world program

class helloWorld
{
public static void main(String args[])
{
System.out.print("Hello World !");
}
}

And save this as test.java.Now after compiling it a helloWorld.class file is generated.But if we compile the same after adding "public" in front of 1st line, it throws error.

public class helloWorld
{
public static void main(String args[])
{
System.out.print("Hello World !");
}
}

but then changing the file name to the name of the class i.e. helloWorld.java, corrects the error.

View Replies View Related

Swing/AWT/SWT :: Execute Main Class Into A JButton?

Mar 10, 2014

how can i execute the main class into a JButton.

Example: Main Class

public class ComparativoV3{
public void loadComparative(String path){
}
public void compareDbs(){

[Code].....

how to set it up the private void CompareActionPerformed(java.awt.event.ActionEvent evt) as the ComparativeV3 main class, not giving it any argument, because the files are load from the arguments section & it reads diferent files with diferent arguments.

View Replies View Related

Jbutton Act Like A Wall That Will Not Allow A Moving Jbutton To Pass Through

Apr 7, 2014

I am trying to have a Jbutton (blocker02) act like a wall that will not allow a moving Jbutton to pass through. I tried using " if (blocker02. getBounds (). intersects(r_wall)) but it hasn't been successful.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.Rectangle2D;

[code]....

View Replies View Related

Clear JButton Will Not Clear Text

May 6, 2014

import javax.swing.*;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;

[code]....

My issues is at the bottom, I can't get the clear button to clear, well it clears but it also show the JOptionPane. I couldn't find the edit button on the page

View Replies View Related

Adding Text To JTextArea From Second Class?

Feb 4, 2015

Basically , I'm trying to make a program that makes the Finch follow the object. I have made two classes :

NewOption52 and FollowClass.

Class NewOption52 contains a method which determines the properties of the GUI. Class FollowClass contains a main method which calls GUI method from class NewOption52 and it also contains several methods which dictates the Finch's behavior alongside with appending text to JTextArea feed.

When I connect the Finch and run the program , a GUI should appear and inside JTextArea should have text which says ""Please Place An Object in front of Finch And Then Tap Finch to Activate!". It didn't happen when I run the program.

Class NewOption52 :

import edu.cmu.ri.createlab.terk.robot.finch.Finch;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.*;
public class NewOption52

[code]....

View Replies View Related

JSoup - How To Get Text From Specific Class

May 14, 2014

I'm trying to get some text from a class but there are more then one classes with the same name and it gives me the text from all the classes... how do I get text from a specific class?

View Replies View Related

Swing/AWT/SWT :: Append Text To Textarea From Another Class

Aug 2, 2014

Class 1 open main frame

Class2 add panel for main frame

Class3 append text to Jtextarea (of panel class2)

View Replies View Related

Text From The Class Game Doesn't Update

May 3, 2014

I have a main class that hold the frame and paints, a class for drawing my game, and an image that is drawn too.
I want to count the amount of times I click on this "android" (right now it counts if i click the screen) but the text from the class Game doesn't update.

androidX = Main.width - android.getWidth();

doesn't work. In my head the image should be inside the borders but it isn't. Have I calculated the pixels wrong or am I missing something?

public class Main extends JPanel{
public static final int width = 600;
public static final int height = 600;
Game game = new Game();
Android android = new Android();
public void paint(Graphics g) {
super.paint(g);
game.render(g);
android.render(g);

[code]....

View Replies View Related

Instantiate Objects Of Class And Writing Them To Text File

Jul 18, 2014

I need to create a new text file and instantiate objects using an array that writes them to a file and working with the array part.

public class NewTextFile
{
private Formatter file;
public void openFile()
{
try

[code]....

View Replies View Related

Java Class Person - Adding Data To Text

May 5, 2014

Your Tester class main method must use an array or an ArrayList of Person objects. It must be populated from a text data file, friends_data.txt. Add the following data to your text file,

Michelle, 12/20/2008, Camilla
Bryan, 3/8/2007, Tom
Camilla, 6/7/2005, Michelle
Tom, 10/15/2007, Bryan
Charlotte, 3/2/2008, Michelle

Each line has the meaning:

-Person name, Person date of birth (MM/DD/YYYY), name of best friend
-Write a Java program that reads in the data from the friends_data.txt file, allocates a new
-Person for each and then stores the newly created object in either an Array or an ArrayList.
-Next print out a report showing the following information for each Person,

1. The Person's name
2. Their popularity counter
3. Their age on May 1, 2014
4. The name of their best friend
5. The age of their best friend on May 1, 2014

Finally, print the name of the most popular Person and the name of the oldest Person.

Person Class

import java.util.ArrayList;
public class Person {
public String personsName;
public String personsFriend;
public String personsBirthday;
public int personsPopularity;
public int popularity = 0;

[code]...

I keep getting this error from the compiler:

System.out.println("Popularity : " + personsOfInterest[i].getPopularityNumber());

"method getPopularityNumber in class Person cannot be applied to given type:
Required: java.lang.String[]; found: no arguments; reason: actual and formal argument lists differ in length.

View Replies View Related

Creating Simple Text Editor - Delete Selected Text Inside Text Area

May 13, 2015

This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....

Here is the code..

package KOSAR2;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related







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