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?
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
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();
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?
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?
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.
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 ?
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.?
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.
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.
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)
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
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.
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?
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.
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.
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?
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?