Swing/AWT/SWT :: How To Make Restart Button Work

Mar 19, 2014

how to make this restart button work. This is what I have so far. I have put the restart button code in red and bold...

package Game;
public class Buttons extends javax.swing.JPanel {
private GameWorld world;
private int restart;

[code]....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Action Listener Does Not Work With Button Click

Feb 22, 2015

I have buttons created on a frame and then I register the listener from a controller in a controller-view relationship.

When I click the button on the face, the action never executes for some reason. I thought maybe there was a problem registering the listener but I can call the buttons doclick() method and it executes as it should. Perhaps I'm overlooking something really obvious here but I can't see it.

btnEight = new JButton( "8" );
// btnEight.addActionListener( controller );
btnEight.setBounds( 212, 90, 41, 23 );
frame.getContentPane().add( btnEight );

and then I add the listener

public void setController( ActionListener theController ) {
Component[] components = frame.getContentPane().getComponents();
for ( Component component : components ) {
if ( component instanceof JButton ) {
JButton button = ( JButton ) component;
button.addActionListener( theController );
}
}

again, when i click the button nothing happens. but if i add the following code

btnEight.doclick()

the actionPerformed invokes in theController as I intended.

You can see the entire project on GitHub so you can see the full context. The controller class contains the listener and the view class contains the buttons.

View Replies View Related

Swing/AWT/SWT :: Make Submit Button Smaller

Nov 12, 2014

make this button:

look more like this one:

I'm using GridLayout for my main JFrame.

View Replies View Related

JSF :: How To Make Focus To Button During Onload If Button Is In TabbedPane

Feb 24, 2015

I am using JS, how we can make focus to a button during onload, the button need to get focus which is in tabbedPane tab Name : (Search Critera1) using javascript.

View Replies View Related

Cannot Get First / Last And Previous Button To Work

Dec 14, 2014

Okay so I have this part done and I cannot get all the JButtons to work. This is my first GUI!

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintStream;
import java.util.Arrays;
import javax.swing.BoxLayout;

[Code] ....

BTW the error is on 310, 311, and 312 and the error is cannot find symbol ....

View Replies View Related

KeyListener Doesn't Work - Button Is Not Displayed

Apr 14, 2015

Why the keyTyped function isn't triggered, when i type a key?

Here is my code:

package main;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
 
[Code] .....

I have noticed, that if i call setVisible(true) before i add the button, then it works, but the button is not displayed... How can i achieve that the button is displays AND the KeyListener works?

View Replies View Related

GUI Phonebook - Getting A Button To Work For Deleting Contact?

Apr 24, 2014

I'm working on a GUI Phonebook and need getting a button to work for deleting a contact. I identified the error I get in the Gui class where it says applyDeleteEntry(); on line 106 with comments. The entries are stored in a .txt file which is created for you.

Main class:

import javax.swing.*;
import java.awt.*;
public class Main{
public static void main(String args[]) throws Exception{
Phonebook mainPhonebook = new Phonebook();
Gui mainGui = new Gui();

[Code] .....

View Replies View Related

Simon Java Game / How To Make GUI Work

Dec 6, 2014

I am trying to make a java Simon game but I cannot figure out how to make the GUI work. I have this so far, but now it just keeps saying I lose and it isn't functioning. It seems the only way I can make it work is having the action listeners in the do loop, but then once a button is clicked, the code errors out.

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

[code]....

View Replies View Related

Make A Splash Screen It Didn't Work

May 10, 2014

I tried to make a splash screen it didn't work.Here is the error message: Exception in thread "main" java.lang.Error: Unresolved compilation problems:

JSplash cannot be resolved to a type
JSplash cannot be resolved to a type

at com.mime.splashscreen.SplashScreen.main(SplashScre en.java:8)

The code is:

package com.mime.splashscreen;
public class SplashScreen {
private static final String Color = null;
public static void main(String[] args) {
JSplash splash=new JSplash(SplashScreen.class.getResource("splash.png"), true, true, false, "V1",
null, java.awt.Color.RED, java.awt.Color.BLACK);
}
}

View Replies View Related

How To Make Hangman Program Work For Phrases With More Than One Word

Apr 13, 2015

I created the following hangman program, but it only works for one word file inputs. How can I modify the program to make it work for files with a multiple word phrase?

/**This program is a basic Hangman game. It takes a word or phrase from a file, and then asks the user to guess the letters in it. The program ends when the user inputs 8 wrong guesses.
*/

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
  Scanner kb = new Scanner(System.in);
  String guess;

[Code] ....

View Replies View Related

How To Add Action Listener To Code To Make Calculator Work

Mar 7, 2014

here is the code i already have made;

import java.awt.*;
import javax.swing.*;
public class EX_7_2 extends JFrame
{
public EX_7_2()
{
setLayout(new BorderLayout(5, 10));

[Code] ....

View Replies View Related

Make Panel Go Away If Button Is Clicked?

Jan 27, 2014

What are a couple of examples to code a button that if it's clicked the panel's visibility is set to false?

View Replies View Related

How To Make A Button That Change The Label

Jan 29, 2014

How can i code this differently so that when i click one of the button it changes the image to the red.jpg or green.jpg?

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class GUI{
public static void main(String[] args){
JFrame window = new JFrame("Test");

[Code]...

View Replies View Related

How To Make Button Clear The Data That User Entered

Mar 25, 2015

package com.example.imc;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

[Code] ....

View Replies View Related

Swing Button That Creates A New Button

Nov 29, 2014

I am creating a mad libs type program. This section of code is for the user to be able to make their own mad lib template (that people will be able to fill out later). The normal blanks in a mad lib are for verb, noun, adjective, adverb, etc. I cam up with 13 or so of these buttons, but it would be nice that if the user wants to add a button that they think we missed, such as 'Person in the Room' or 'Silly Location'...that the user would be able to do this. I sort of pictured there being a button that says 'add button' or something like that. Is there a ways to do this with the way I've set things up?

public class MadLibs {
public static void main(String[] args) throws IOException {
////////////////////
//TEXT PANE WINDOW//
////////////////////
//Set up a JTextPane object : The JTextPane is a specialized form of the JEditorPane
//designed especially for the editing (and display) of styled text.
final JTextPane pane = new JTextPane();

[Code] ....

View Replies View Related

How To Restart A Loop At A Certain Point

Jun 8, 2014

I made a blackjack code in java and I need to find a way to replace the place where I added a system.exit with a way to ask the user if they'd like to play again and restart the loop, keep in mind that I don't need the program to restart as I'd like to keep the value of their chips considering if they've won or lost.

Secondly, because it is a blackjack code, when it deals the cards, I would like for it to also print out K, Q or J but still consider it the number 11. Can I make an Ace count as 1 and 11?

One last question, is there anyway to add the suits of the cards such as (clubs, spades etc.) but the actual signs and if the signs aren't possible at all then the letter ('C', 'S', 'H', 'J') will have to do I guess.

import java.util.Scanner;
class Blackjack {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
Scanner num = new Scanner (System.in);
System.out.println("Welcome to Blackjack!");

[code]....

View Replies View Related

Buffered Image Alpha RGB - How To Make Alpha Work

Apr 9, 2014

So what I do normally is draw the bottom layer of grass, and when I draw the second layer with trees, the tree layer has a shadow, that shadow doesn't go ontop of the grass layer, but instead it overwrites the grass layer aswell and I've checked the color codes, the shadow has combined with white, not the first layer.

it's obvious that that's not how alpha works then, how do I do it?

View Replies View Related

How To Restart Program Once Answer Has Been Found

Oct 29, 2014

I am creating a body mass index calculator and i was wondering how i could make its so that the program resets itself once the BMI has been found....

My code is below...

package bmiCalculatorSource;
import java.util.Scanner;
public class BMICalculator {
public static void main(String[] args) {
final double KilogramsPerPound = 0.453;
final double MetersPerInch = 0.026;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Trying To Get GridBayLayout To Work

Mar 20, 2015

I am trying to get the gridBagLayout function to sort my code to look like the attached image. I am having trouble figuring out how to do it or even where to start. My code can be seen below and this was as far as I could get on my own.

// Using JSlider to size an oval.

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeListener;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Calling Method Does Not Work From JMenuBar

Nov 6, 2014

I have a paint program in Java where I can draw objects. The objects are stored in an arrayList. In the menubar the user can chooce "Back", which means the last item in the arrayList is removed. After that I want the program to loop through the arrayList and draw the remaining items.

My problem is that when I try to do that it will not work from the menu (menuItem2). If I instead add the code to one of the colorpanels (yellowPanel), from where the user can pick colors, it works fine.

menuItem2 uses ActionListener and yellowPanel uses MouseListener.
public class PaintProgram extends JFrame implements ActionListener {

public ArrayList<Draw> shapeList = new ArrayList<>();
int startX, startY, endX, endY, w, h;
private JPanel topPanel;
private JPanel bottomPanel;
private JPanel magentaPanel;
private JPanel greenPanel;
private JPanel bluePanel;
private JPanel blackPanel;

[code]....

View Replies View Related

Swing/AWT/SWT :: Search For A Key In Properties File - Jbutton Won't Work

Aug 26, 2014

I have a properties file with key values in it, now when I use my search box to search for a key in the properties file to check whether or not it is there - I can't get it to check and return the key value if it is theere. I've tried a few methods but keep getting a null pointer exception when it hits line 15 in the code all the time so I'm stumped at the minute.

My text field is called textFieldSearch

This is my button code

JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//search button
//find selected comman
String key_name = textFieldSearch.getText();

[Code] ....

This is my method code

public void FindSelectedKey()
{
if(textFieldSearch != null)
{
properties.getProperty(key_name == textFieldSearch)
}
}

View Replies View Related

Save JTable Contents So Table Data Remains After Program Restart?

May 22, 2014

how I would achieve the concept of saving the contents of a JTable, so even after program restarts, the table would retain the data. I am developing a utility that will be a password storage book. The user enters passwords and they are stored in a JTable. Currently, the table resets whenever the program is restarted, however I would like it to keep it's data. URL....

View Replies View Related

Swing/AWT/SWT :: Making A Custom Cell Renderer Work In A JTable?

Jan 24, 2014

Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:

MonthYearTableCellRenderer renderer = new MonthYearTableCellRenderer();
tblView.setDefaultRenderer(Date.class, renderer);
for(int i = 0; i < 60; i++){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.MONTH, i);
tableModel.setValueAt(cal.getTime(), i, 0);
}

The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.

View Replies View Related

Swing/AWT/SWT :: Paint Circle In Frame On Key Press - Cannot Get KeyListener To Work

Nov 3, 2014

I wanted to try out using a KeyListener to read what key I press so it can paint a circle in my frame, but I can't get it to work?

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: MouseListener Doesn't Work If JList Has Custom CellRenderer

Nov 9, 2014

I have a JList<Object> in my code (it actually takes JLabels) called imageList, and I've given it a custom CellRenderer using the following code:

cellRenderer = new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public Component getListCellRendererComponent(JList<?> list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {

[Code] .....

However, when I click anywhere on the JList, nothing gets printed to the console, which suggests that the mousePressed() method isn't being invoked. I think it's a problem with the CellRenderer, because I have similar code elsewhere that works, the only difference being I don't use a custom CellRenderer.

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related







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