Adding Imports - Change To Swing Format

Apr 20, 2014

I made a game but i didn't add imports, i have been told i need to have imports and it needs to be in a normal swing format or it will not pass . How to change my code to swing format?

My code is

public class TextTwist extends javax.swing.JFrame
implements java.awt.event.ActionListener

// hard code, should be picked from a Problem class
private String[] letters = {"F","O","C","I","E","F"};
// hard code, should be picked from a Problem class
private String[] solutions = {"ICE","OFF","FOE","FOCI","OFFICE"};
 
[Code] ....

How do i get the program to move on to the next one String?

View Replies


ADVERTISEMENT

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

View Replies View Related

Use Of Imports

Mar 25, 2014

I am a bit confused on the use of imports. I am reading a book on java and in one of their examples it starts a program with;

import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

The question I have is on the awt import.If I have import java.awt.*;I assume that that will include all I need under the awt directory but the next line, import java.awt.event.* why the java.awt.*; does not include the .event.*; directory as well?

View Replies View Related

Finding Necessary Imports

Feb 8, 2014

where to find the following import the files?

import de.uos.fmt.musitech.data.score.NotationStaff;
import de.uos.fmt.musitech.data.score.NotationSystem;
import de.uos.fmt.musitech.data.score.NotationVoice;
import de.uos.fmt.musitech.data.score.ScoreNote;
import de.uos.fmt.musitech.data.structure.Context;
import de.uos.fmt.musitech.data.structure.Note;
import de.uos.fmt.musitech.data.structure.Piece;
import de.uos.fmt.musitech.data.structure.linear.Part;
import de.uos.fmt.musitech.score.mpegsmr.Attributes;
import de.uos.fmt.musitech.utility.math.Rational;

View Replies View Related

How To Manage Imports

Feb 27, 2015

My first Java project contains 30+ imports, all of which are for specific classes -- I'm using NetBeans and whenever I instantiate a new, unimported class I just click on the "light bulb" and tell it to import. I'm only now starting to worry about code management and conventions.

As you can imagine, many of these imported classes live in just a few packages, like awt and file.nio. It's starting to make my code a little cluttered. In the real world, what is the convention for import statements? My instincts tell me I should just import using the .* wildcard, but how do professionals do it? If an experienced programmer were to pull my code from Github, what would they want or expect to see in the import lines of code: a bunch of specific imports, or wildcard imports?

View Replies View Related

Wildcard Imports May Lead To Ambiguities?

Jul 31, 2014

The followings are what I see just now.....
//******************************************
Ambiguities

Wildcard imports have one problem though: they can lead to ambiguities when classes with the same name exist in two packages you import via wildcard.

Imagine the following two imports:

import foo.*;
import bar.*;

Now you want to use the class foo.Node but there is also a class bar.Node. Now you need to use non-wildcard imports to resolve the ambiguity that would happen otherwise.

View Replies View Related

Swing/AWT/SWT :: How To Format Value In Table Model

Nov 14, 2014

public PurchaseTableModel() {
try{
//establish connection
conn = DriverManager.getConnection("jdbc:odbc:SupplierDS");

stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);

[code]....

I get the value from database and display in table , price value will show 6 decimal and date value will show date and time.What to do to show only 2 decimal places and only date e.g. 1/1/2014 in the table ?

View Replies View Related

Swing/AWT/SWT :: Generating UNCOMMON Format File Using Java

Oct 17, 2014

Well I want to generate a license key for my software product. I'm aware of Google's Guava Libraries for generating alpha numeric license keys. But I'm thinking it to do in a different way without using any such libraries or specifically guava libraries. Till now this is my plan that,

1. Get a MAC ID / IP Address of the system in which the application will be installed and ready for it's first use.
2. Store that MAC ID in a UNCOMMON File format in client's PC only.
3. And what should be the next step.?

View Replies View Related

Swing/AWT/SWT :: Number Format Exception - Empty String

Mar 8, 2014

This is the exception message I am getting when I run the program and I select a job from the check box and enter an hour amount.

import javax.swing.*;
import java.awt.*;
public class HourPanel extends JPanel {
private double hours;
String textField;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Why Does ItemStateChanged Only Change Just Once

Mar 5, 2015

I have a strange problems. Perhaps some of you already have had this problem before.

I have method which is suppose to check if the itemstate has changed. It ONLY works ONCE?

Thereafter, it does not matter how many times I changed the selection of the ComboBox.

Basically I have two Comboboxes.

1. If Combobox 1 is selected (e.g. Dogs, Cats)
2. Then get information from what ever the item from ComboBox 1 is selected, and display on ComboBox 2. (Dog Name, Cat Name etc)

E.g.

So If I selected Dogs on Combobox 1
Then display the Dog Names on Combobox 2.
If I then change and select Cats on Combobox 1,
then display Cat Names on ComboBox 2.

View Replies View Related

Swing/AWT/SWT :: For Loop Did Not Change Value

Dec 11, 2014

I like to list all pdf files of the mentioned directory, but I only get all time the first pdf file...Where is my error? I really don't get it...

new Thread() {
@Override
public void run() {
String directory;
directory = "C:UsersTommyDesktoppdf";
File inputFiles = new File(directory);
CopyOfSettingsGui.this.running = true;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Validation Phase - Make Sure Textboxes Are Not Empty And In Correct Format

May 20, 2014

I have a question with this gui project I am building, I have gotten the code to work in very basic forms such as the main part of calculations and etc. But now I am in the phase of validation to make sure the textboxes aren't empty and are in the correct format. I have done alot research already. I would like to use a Joptionpane to warn the user of an invalid entry. But I have tried many different methods and I can't seem to get them to work.

private void calculateActionPerformed(java.awt.event.ActionEvent evt) {
double loanAmt;
int years;
boolean validData;
double rate,total,calcRate,payment,amount,numMonths,totalPayment,paymentRounded,numMonthsRounded;

[Code] .....

When ran I get these errors: (only copied a few of the main lines)

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "p"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1241)
at java.lang.Double.parseDouble(Double.java:540)
at car.loan.NewJFrameCarloan.calculateActionPerformed(NewJFrameCarloan.java:228)
at car.loan.NewJFrameCarloan.access$500(NewJFrameCarloan.java:17)
at car.loan.NewJFrameCarloan$6.actionPerformed(NewJFrameCarloan.java:106)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)

View Replies View Related

Swing/AWT/SWT :: Stopwatch - User Select How Timer Format Is On Java Beans

Mar 17, 2014

I am working on a java bean, on a stopwatch

private String displayFormat = "%02d:%02d:%02d";// produces 00:00:00 hour:min:seconds
public void timerHasChanged() {
currentTime = System.currentTimeMillis();
// How long has been taken so far?
long secsTaken = (currentTime - startTime) / 1000;
long minsTaken = secsTaken / 60;
secsTaken %= 60;
long hoursTaken = minsTaken/60;
minsTaken %= 60;

Formatter fmt = new Formatter();
fmt.format(displayFormat, hoursTaken, minsTaken, secsTaken);
timerJbl.setText(fmt.toString());

How would i code the get and set method for format, so in property tab a user can choose if they want the timer shown in seconds, or minutes or hours or seconds&minutes

View Replies View Related

Swing/AWT/SWT :: How To Change Font For JOptionPane

Apr 21, 2014

I am quite familiar with using JOptionPane and its various displayXDialog() methods and reasonably familiar with changing fonts.

I have a JOptionPane.displayMessageDialog() that is working fine but I decided to make the font larger.

I found an example from which I coded:

Font font = UIManager.getFont("OptionPane.font");
UIManager.put("OptionPane.font", new Font(font.getName(), font.getStyle(), 24));
font = UIManager.getFont("OptionPane.font");
JOptionPane.showMessageDialog(this, "Welcome to Mover", "About Mover", -1); // no icon

After the UIManager.getFont() call after the UIManager.put() call, font shows the new font size of 24, but the showMessageDialog() dialog still has the default font.

And yes I understand that, when this works, it will affect every JOptionPane in my program.

I also tried:

Font font = UIManager.getFont("OptionPane.font");
JOptionPane message = new JOptionPane("Welcome to Mover", JOptionPane.INFORMATION_MESSAGE);
JDialog dlg = message.createDialog("About Mover");

[Code] ....

This gave me a dialog with the default font and an unwanted icon.

So I tried

// both
Font font = UIManager.getFont("Dialog.font");
// and
Font font = UIManager.getFont("JDialog.font");

and planned to use that font in my setFont() call but font was null.

View Replies View Related

Swing/AWT/SWT :: Change Size Of Entire GUI?

Feb 4, 2015

I built a GUI and after testing it on various platforms I think I would like to make it bigger by a factor of 2.2 or so.

Is there an easy way to just enter the factor 2.2 and have the GUI change by that factor?

I have over 50 components in the GUI. Ideally each one would just enlarge by the factor including the fonts.

This was my first (and only so far) java program. I didn't know anything about layout managers. I used netbeans and it generated all the code.

View Replies View Related

Swing/AWT/SWT :: How To Change JFrame Size

Jan 14, 2015

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code].....

View Replies View Related

Swing/AWT/SWT :: Change The Blue Color?

Apr 6, 2014

When I click a JButton, it will become blue momentarily. Is it possible to change the blue color? If yes, how?

View Replies View Related

Swing/AWT/SWT :: How To Change Jbutton Color While It Is In Focus

Jan 27, 2013

refer to this code~

import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;
import javax.swing.JButton;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Change CheckBoxTree From FileSystemView To File

Mar 5, 2015

I am trying to use a CheckBoxTree that has been already created here: [URL] .... The problem which this JTree is that is uses FileSystemView for the root directory and as far as I know it does not set any root directory.

So I want to have the ability to give it a root directory. for example: new File("C:Temp") So when the tree appears , it lists files and folders in the provided address, and not the entire system.

The code is available in the provided GitHub. I tried to replace all FileSystemView fileSystemView in constrictors and bodies with File file to make it working. It worked but ended up with errors such as not showing the file icons.

How to modify it correctly or if there is any better way to convert FileSystemView to File?

View Replies View Related

Swing/AWT/SWT :: How To Change Background Color Of Panel

May 3, 2014

Program is not working. I want to use buttonPanel object in ColorAction class and the process is unknown to me .

package button;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonFrame extends JFrame
{
public JPanel buttonPanel;

[Code]...

View Replies View Related

Swing/AWT/SWT :: Cannot Get ActionListener To Change JLabel Text

Apr 24, 2014

I am trying to write an application where if you click and hold down on 1 button and move the mouse to another button and release the text on the 2 buttons should be switched around.I have a print line so I can se the text are supposed to get switched around but it is just not happening in the GUI.

I attached all my code in case the flaw was to find somewhere else in the code, but the functionality I am working on is the lines 76 to 121.

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Change Action After 1st JButton Click

Aug 3, 2014

I am relatively new to java. . 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.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;

[Code] .....

View Replies View Related

How To Change Fonts And Font Size In Swing

Feb 10, 2014

So, I have a game. I would like to make a game where you press "start" and THEN it starts. Also, I want to have collision with triangles, not just squares. The way I handle collision right now is with if statements, if the object is within the other, game over.How would I do collision with triangles? Lastly, how do I set a high score? how to change fonts and font size in swing?

View Replies View Related

Swing/AWT/SWT :: Event To Detect Jframe Change

Aug 13, 2014

I would like to detect when the user change de JFrame. I make:

public class UI implements ActionListener, ComponentListener, DocumentListener, MouseListener{

private JFrame ventana;
private JTable table;
private JPanel panel;
private JScrollPane tableScrollPane;

[Code] ....

I put componentResized but when I change JFrame I cant see the string that I put in the method.

View Replies View Related

Swing/AWT/SWT :: Getting Icons To Change Size With Window Resize

Jan 19, 2014

I'm using a jpanel with an 8 by 8 grid layout of jlabels to which I'm adding images to represent a chess board. At first, I was using the ImageIcon class to initialize my icons, but as soon as I added these icons to the labels, the labels no longer changed size with the window (which I want to happen). URL...

So I copied in the class, and initialized a different set of icons using the stretch icon class (specifically, the method that allows you to initialize a stretch icon from a filename), however, when I use these stretch icons, the result is the same. Is something wrong with the class, or with my implimentation of it, and how would I fix this?

View Replies View Related

Swing/AWT/SWT :: Change Location Of Component Using Grid Bag Layout

Jun 13, 2014

How to change the location of a grid bag positioned component after it's already been added to the layout earlier?

Example is if I want component 1 to change from row 1 to row 2.

View Replies View Related







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