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.
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;
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.
[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");
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.
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);
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? }
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?
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?
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.
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.
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 }
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:
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.
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.
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(); } }
how run the executable jar files using JButton from another class file.I need, when i click the button then the executable jar file should be and display the output.
I cannot...(actually do not know) how to change the actionlistener (actionPerformed) after the second click in an array of JButtons. This is how the program performs right now.
On the 1st click on the grid, the border of the button clicked will change to 'blue' and another button will change its boarder to 'red'. on the next click the same action is performed.
What I need is to change action when the 'red' bordered button is clicked, lets say change the color of the buttons from the 'red' to the 'blue' buttons.(x 3 buttons).
The logic about how to perform the final result I think I can do on my own but my problem is how to change the action when the red bordered button is clicked.
I want the Jbutton Button1 icon to change when i click it howerer i am getting the error can not find symbol for the code in the actionPerformrd method.
I've tried multiple things but I can't seem to figure out how to get my JButton over the background graphics. On lines 104-108 I create the JButton I need to put on the screen, though I have no clue how to draw it. How I can paint over this background and have my button stay there?
public static final int WIDTH = 1024; public static final int HEIGHT = 640; private Thread thread; private boolean running; private BufferedImage image; private Graphics2D g;
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);
How to get my program to display a piece of text (upside down) on the first button press, and then display it right-side up on the second button press. I've looked all over the internet and I can't seem to find a example that fits my situation.
Here is the code:
package org.CIS407.Lab10; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JUpsideDown extends JFrame implements ActionListener
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