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
ADVERTISEMENT
Apr 7, 2014
import java.awt.*;
import java.awt.event.*;
import javax.swing.ImageIcon.*;
import java.awt.Font.*;
import javax.swing.*; //import java swing to use the Jframe etc
public class MathQuiz extends JFrame implements ActionListener
[Code] .....
I have 2 JButtons on my JFrame and i would like to add a function to it when i click on them.
I would like the JButton calculator allow me to open another JFrame if thats possible and i would like the JButton Exit allow me to exit the current Frame.
View Replies
View Related
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
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
View Related
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
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
Nov 18, 2014
Having trouble adding Class (Dollar) objects to a HashSet (money), i have done this before with arraylists and i understand that HashSets are different in that they cannot contain duplicates. Currently when this code is compiled i am getting "null" printed when I run the "howFullDatWallet" method.
import java.util.*;
public class Wallet {
private HashSet<Dollar> money;
private int walletSize = 0;
private int walletFiller = 0;
/**
* Constructor for objects of class Pocket
*/
public Pocket(int walletCap)
[code]....
View Replies
View Related
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
Dec 2, 2014
I need to add from what is selected in some check boxes to an array that is in another class, but I can't get the other class to be called correctly.
I need to get the toppings that are selected from the check boxes added into the array that is in the calculations method.
Calculations method
Java Code:
import java.util.ArrayList;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
[Code] .....
View Replies
View Related
Jan 23, 2015
I'm trying to fill my jtable with an arraylist. The problem is the jtable is in an extended class and the arraylist in the mainGUI. Now how can I fill the jtable with the arraylist?
That's the arraylist in my MainGUI
BufferedReader in = null;
ArrayList<String> data = new ArrayList<String>();
try {
in = new BufferedReader(new FileReader("1.dat.txt"));
String str;
while ((str = in.readLine()) != null) {
data.add(str);
[Code] ....
View Replies
View Related
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
Sep 19, 2014
I am trying to create a GUI interface in swing which consists of four classes: a GUI class, which creates a main JPanel, a label, and a JList, which it takes from the second class, a MovesList class that contains a JList and the stuff needed to interface with it. It also has a main class, which basically just creates an object of the GUI class for the main window, and an Other class from which I would like to be able to add an item to the JList. I created methods in the MovesList class to get each component (like getMoveslist, or getMovesListScrollPane), which I then used to create the JList in the GUI class. I also created an addMove method so that I can add an item to the JList from any class through a MovesList object. However, this addMove method only works when called from the GUI or MovesList classes -- it does nothing when I collect from the Other class.
Here is my code:
//Main class
public class TestProject {
public static void main(String[] args) {
GUI mainWindow = new GUI();
mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
[Code] ....
When I run this code, I get a window with a JLabel that says "Moves," and a JList that contains five elements -- test 1-test 5, but not a sixth "test from other class." ( using the add move method ) However, when I click on the window, the addMove method is also called, and successfully adds "test 6" to the list.
View Replies
View Related
Apr 30, 2014
for my assignment I am to only add the sort and total inventory methods in the inventory class. And not create an array in the inventory class at all. My inventory class should contain all the variables needed to use with the two new methods: sort and calculate total inventory.By not creating any array in the inventory class and not touching the variables at all.
What I have came up with is:
public class inventory
{
private int prodNumber; // product number
private String prodName; // product name
private int unitsTotal; // total units in stock
private double unitPrice; // price per unit
private double totalInventory; // amount of total inventory
// initialize four-argument constructor
[Code] ....
The error message I get is:
F:Java Programminginventory.java:62: error: cannot find symbol
return prodName.compareTo ( s. getprodName() );
^
symbol: method getprodName()
location: variable s of type inventory
1 error
View Replies
View Related
Apr 26, 2015
[attachment=38859:bcourt.jpg]I/m not used to Timers, so this will be my first time using it and I don't know how. I've been searching the internet for an hour but I can't find an answer into it. I'm currently doing a basketball game which has a Buttons (Shoot,Dribble,Hold) and I need those timers for my buttons to work. Her's the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BasketBall extends JPanel implements ActionListener
{
JButton shootButton = new JButton("SHOOT");
JButton drbblButton = new JButton("DRIBBLE");
JButton holdButton = new JButton("HOLD");
[Code]...
View Replies
View Related
Apr 2, 2014
Is it possible to go from one method to another when a jbutton is clicked?
View Replies
View Related
May 25, 2014
I have a Jbutton in my application named as SUBMIT,on clicking SUBMIT the text of jButton changes to ABORT. I wish to apply enter key listener on both the SUBMIT and ABORT button in my applcation, however I am not able to get the text of the button in key listener,so that i can apply my code based on the current text of Button.
View Replies
View Related
Aug 3, 2014
I have a jButton that when the action perform runs it only does part of the tasks some of the code doe not appear to run and i just can not figure out why i have tried wrapping parts of it in an if statement and it still do not run so here is the code behind the button:
in the code the parts that do not run are jTextField10.setText("Working Please Wait"); and jButton15.setVisible(false);
what i am expecting to happen is the text field has the words Working Please Wait placed in it , this does not happen and the button should be hidden to prevent it being clicked a second time again this does not happen
the rest of the code works as expected
InputStream inStream;
OutputStream outStream;
try {
File afile = new File("C://templates//amendments.xls");
File bfile = new File("C://amendments.xls");
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
[code]....
View Replies
View Related
Oct 11, 2014
I am having right now is that I don't know how to stop my music from playing? I am making a Connect 4 game with some audio to make it intuitive. Below is my code. This is my Music method.
public static void Music() {
try {
File music = new File("C:\Users\Ken\workspace\Assignment1\src\Mario1.wav");
AudioInputStream audioIn = AudioSystem.getAudioInputStream(music);
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
[Code] ....
I called this method into a JButton i implemented into my main GUI.
if (e.getSource() == SoundOn){
Music();}
if (e.getSource() == SoundOff){
//What do I put here?
}
There is the method and my JButton.
View Replies
View Related
Aug 19, 2014
How do i parse a String of text in a JTable Cell to work as a button?For example lets say a row of IDs such as 1,2,3,4,5,6 id like the whole column to parse as JButtons that are titled 1,2,3,4,5,6..Id like to then use these buttons to call a function with the title as a parameter.Its just a simple row of entries where the button will open up an edit screen to edit the corresponding clicked entry.So how do i parse them as buttons for a start?
View Replies
View Related
Sep 25, 2014
I'm not sure what I'm doing wrong but none of the buttons will show below. I tried using .add with the container name but it kept giving me an error. When I just put add.(); it seems fine but then nothing shows. Is there something I'm missing that's required?
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@SuppressWarnings("serial")
[code]....
View Replies
View Related
May 20, 2014
import java.awt.GridLayout;
import javax.swing.*;
public class Screen
{
JButton start;
JButton reset;
JButton box[][] = new JButton[20][20];
Screen()
[Code] ....
I am trying to place the buttons on the bottom. I tried a few different things but the grid layout keeps grabbing it and making them a part of the grid at the button.
View Replies
View Related
Mar 5, 2014
I was suspecting I had a jButton not working, so I added a console print to test. See below. When I click the button, the console doesn't display anything. Am I using the button wrong?
private void jButtonUpdateItemsMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}
I have also tried the following with the same results (or lack of).
private void jButtonUpdateMajorDeckItemsActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}
View Replies
View Related
Jun 21, 2014
I'm a beginner in java. I would like to ask, how to insert JButton on JTable..
View Replies
View Related
Feb 23, 2014
Recently I have been working on an executable launcher. I tried to get the executable icons and set them on the JButtons. Still there are some problems. Here is a part of the code:
try {
button[i].setIcon(FileSystemView.getFileSystemView().getSystemIcon(new File(getConfig("path." + (i+1)))));
}
catch (NullPointerException ex) {
}
Here the getConfig() method is already defined to get a string in a "properties" file. However, the icons are very small and they don't fill the entire button.
How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically filled the button)? The frame will not be resized.
Here is the whole code...
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.io.File.*;
[Code] ....
View Replies
View Related
Apr 10, 2014
Actually i want to develop a game for that i need a background with a image and over this background i want to move some objects (which are images) and also want to add some button.
Here is my Code.
The Main Class
package last;
import java.awt.*;
import javax.swing.*;
public class Last extends JFrame{
public static void main(String[] args) {
Last l =new Last();
l.setSize(900, 600);
[Code] .....
When i execute the above program only the background image is shown.
View Replies
View Related
Apr 22, 2015
im trying to make a gui im trying to add a new jbutton for every empty cell in the array, and for some reason its giving me array index out of bounds error, this is what i have, im trying to to do it in an 80 by 80 array.
public JButton[][] buttons = new JButton[80][80];
public void addButtons(){
for(int i=0;i<buttons.length;i++){
for(int j=0;i<buttons[i].length;j++){
buttons[i][j]= new JButton();
}
}
}
View Replies
View Related