Classing White Space As Invalid Name When Close Button Is Pressed
Oct 29, 2014
I have a filechooser that works how it should and if anyone enters anything with a dot that isnt .xml it shows an invalid file name message. However when I dont choose a file and press cancel it still says that because when my boolean hits false it's the first thing it hits in that section of code.
if(!writeSuccess)
{
//display output messages in JOptionPane
JOptionPane.showMessageDialog(null,"Error, file name invalid", "Error", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null,"Export successful", "Success", JOptionPane.INFORMATION_MESSAGE);
//close the form
me.dispose();
}
If I want it to just close down without it saying anything is there sort of if statement I could do that would prevent this? But if it is an invalid file name it will still show that message?
View Replies
ADVERTISEMENT
Apr 11, 2014
The title says it all and i'm a fairly new java programmer but here is the code:
package TestVersion;
import java.awt.Color;
import java.awt.Graphics;
[Code]......
I think i need a variable or something oh and here is the 2 other classes, the keylistener one:
package TestVersion;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
[Code].....
View Replies
View Related
Feb 3, 2014
for example, I want to pass 'Hello Word.docx' and 'Winston' (both without quotes) as a command line argument as I execute the main method
Is it possible to pass 'Hello World.docx' as a whole word?
View Replies
View Related
Mar 15, 2015
I am able to update the array holding the items but I don't know how to refresh the JList to include all the new items in the array.
Code for GUI:
import java.awt.ScrollPane;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ListView extends JFrame{
HobbyList stuff = new HobbyList();
[Code] .....
View Replies
View Related
Dec 4, 2014
Ok, so I am trying to learn about JFrames and JPanels. I have figured out buttons, layouts, etc. What im having trouble with is accessing the label object from the ButtonHandler class since it is static and I need my JLabel to be non-static so that it can change. Basically, I want JLabel to change to a pre-determined text string once a button is pressed. Here's what I have so far
package makewindow;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
[code]....
View Replies
View Related
Dec 27, 2014
I have a VBox with 20 buttons and I have this style applied (menu.css) (only for VBox wrapper):
.button:focused {
-fx-background-color: #0768A9;
-fx-text-fill: #FFFFFF;
}
But when I pressed other button outside the VBox the style disappears, because the other button get the focus.
How I can do to keep the last button pressed with a custom style? (Only for buttons containing the VBox).
View Replies
View Related
May 4, 2014
I am quite new to developing Applets in java. I recently made an applet that will play a particular sound whenever a button is pressed. The sound files are placed in the same directory as the applet class file and i access them by using
AudioClip clip=getAudioClip(getCodeBase(),"A.wav").
The Applet runs fine in the appletviewer but whenever I try to open it using any browser like Chrome,IE,Firefox the applet loads but sound isn't played. I checked the java console and it showed
"java.security.AccessControlException: access denied ".
My questions are:
1. How do I allow the applet to get access to those files?
2. When the Applet is running from the local file system why CAN NOT I access those resources via getCodeBase() ???
3. I googled and found that I can sign a JAR and that can have full access to the computer. But how do I create a JAR from an applet (which has no Main method) while it asks me to point to the main class in the manifest?
View Replies
View Related
Jul 1, 2014
I'm on windows 8 and I want to use notepad or notepad++ to simulate the press of the space bar every 15 minutes so my computer doesn't auto lock.
View Replies
View Related
Jun 9, 2014
I am making a game in java and i want to make a title screen. What I am trying to do is make a jpanel and load another jpanel when a button is pressed in one of the japenls. Here is the code for the runner
import java.awt.BorderLayout;
import javax.swing.JFrame;
public class Runner extends JFrame {
// Have these set up so they can be seen everywhere
public static final int GAMEWIDTH = 540;
public static final int GAMEHEIGHT = 710;
static boolean loading = false;
[Code] ....
here is the code for the jpanel that loads the other jpanel
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
[Code] ...
How do load a jpanel when a button is pressed in another jpanel
View Replies
View Related
May 11, 2014
import javax.swing.*;
import java.awt.*;
public class PRJ04 extends JFrame {
public static void main (String [] args) {
PRJ04 frmApp = new PRJ04();
PanelChart pnlChart = new PanelChart();
[Code] .....
When I comment out the adding and setting of the pnlChart on my main driver, the pnlPopulationInputs shows up fine, and it runs ok. When I add the pnlChart I get errors like crazy and a white screen. My errors:
Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero
at PanelChart.drawChart(PanelChart.java:45)
at PanelChart.paintComponent(PanelChart.java:24)
at javax.swing.JComponent.paint(JComponent.java:1054)
[Code] ....
Once more with this one, I refer back to our in class example. Our programs are set up the same, yet he has no issues with the "/ by zero" exception.
View Replies
View Related
Jul 27, 2014
What I am doing is loading a new image from resources in my project, so that I can get the size. Using this, I create a new BufferedImage with those dimensions. The following code is what I am using to take the original BufferedImage, and scale it.
Java Code:
public ImageIcon getBackImage(){
before = new BufferedImage((int)img.getWidth(null), (int)img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
int w = before.getWidth();
int h = before.getHeight();
try{
URL url = getClass().getResource("/Blue_Back.png");
before = ImageIO.read(url);
[Code] ......
The scaling seems to be working fine, but what I have noticed is a line of approximately 10 pixels at the top of the image. I took the original image and blew it up to ensure that I wasn't just enlarging undesired portions and this wasn't the case. I then tried to fetch a subImage of the BufferedImage, and that also left the padding at the top. Is there something I am missing that is placing this undesired padding at the top of my bufferedImages ?
View Replies
View Related
Mar 1, 2014
My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use
System.out.print((matrix[i][j] + " ").replaceAll("^s+", ""));
It trims every thing including the spaces I needed for my matrix. So where should I put replaceAll("^s+", "") ?
private static void printMatrix(int[][] matrix) {
System.out.println();
System.out.println("Matrix:");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
View Replies
View Related
Apr 28, 2014
When I open applications specially high graphics applications, the screen flashes with whole black display with a number of horizontal white lines then after 2 or 3 flashes it opens the desired program. What is the cause, is it low graphics memory, physically damaged screen or ?
View Replies
View Related
Nov 19, 2014
I'm stuck with a problem. The code below generates a coloured image.
//Setting the size of the graphics window
final int WINDOW_DIMENSION = 200;
final int SIZE_FACTOR = 3;
EasyGraphics generate = new EasyGraphics(WINDOW_DIMENSION*SIZE_FACTOR,WINDOW_DIMENSION*SIZE_FACTOR);
//Constructing the arrays
char[][] firstArray = new char[WINDOW_DIMENSION][WINDOW_DIMENSION];
char[] secondArray = scan.toCharArray();
[Code] ...
What I would like to do is generate a picture which is mostly white but the colour boundaries of the original picture are in black. I tried using the code below but it doesn't produce what I wanted.
for (int a = 1; a < WINDOW_DIMENSION; a++) {
for (int b = 1; b < WINDOW_DIMENSION; b++) {
generate.setColor(0,0,0);
if(firstArray[a][b]!=firstArray[a-1][b] || firstArray[a][b]!=firstArray[a][b-1])
generate.setColor(255,255,255);
generate.plot(a,b);
}
}
View Replies
View Related
Jun 24, 2015
This screen appears for a second and after this, it shows up normal app screen. How I can solve this issue? When I open app: after this
View Replies
View Related
Feb 1, 2014
Here is the code, I just wanted to draw a simple yellow rectangle in white background...
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class NewEmpty extends Jframe {
Rectangle test = new Rectangle(100,100,100,100);
public NewEmpty()
[Code] .....
Errors in the compiler ( i think there's something wrong with that Jframe)
init:
deps-jar:
Compiling 1 source file to C:Users****Gametestbuildclasses
C:UsersMarcoGametestsrcgametestNewEmpty.java :6: error: cannot find symbol
public class NewEmpty extends Jframe {
[Code] .....
5 errors
BUILD FAILED (total time: 0 seconds)
View Replies
View Related
Aug 21, 2014
I am very much new to Java. I have just started learning event handling. Currently I am learning about Key Events. And am learning by doing. Well that is how one could learn anything in fact. I want to write a program in which the currently loaded image in the panel of a frame changes upon a key press say "Enter" or any other key.
View Replies
View Related
Apr 17, 2015
I have this swing code here:
//dark elixir
Panel panel_4 = new Panel();
config.add(panel_4);
JLabel del = new JLabel("Starting DE: ");
panel_4.add(del);
[code]...
It all displays well etc but if I change the value of one of the fields then I'm not allowed to change the JCombox field anymore.
View Replies
View Related
Dec 1, 2014
If I "embed" a ProgressIndicator inside a ListView it has an ugly border and a white background. It looks like there's a TextField below the ProgressIndicator.
Why does it behave like that and how to solve it so that the progress indicator is transparent.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.ProgressIndicator;
[Code] .....
View Replies
View Related
Nov 9, 2014
i've got this code that i cant get to work as i want it to. when its exported and i run it the file i wants gets created but when i open the file there is a single number like 999998000001
import java.io.IOException;
import java.io.PrintWriter;
public class mainHej {
public static void main(String arg[]){
[code]...
View Replies
View Related
Jul 10, 2014
For every stream that we create for java i/o we write at the end in finally block
finally
{
if(is!=null)
{
is.close();
}
}
It works
my question is as per syntax in if (is!=null) this means that if is means stream contain some value then close it(!=null)
then how it in my opnion it should be like (in logical way)
if stream contain nothing then close it
if(is==null)
{
is.close();
}
I am confuse about working this line
View Replies
View Related
Sep 25, 2014
I am unable to clear disappear the background of .png image added in a translucent JPanel. I have tried it using JLabel but the image added is with white background. How can i get rid of this white background...
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class HomePage
{
JFrame frame;
JPanel pnl1, pnl2, pnl3;
JLabel lbl;
[Code] .....
View Replies
View Related
Apr 7, 2014
I have a class that implements JComponent and draw a rectangle and if a key pressed(for example UP) I want to draw it up, and then when down key pressed to draw it down... But I want not only to disappear, but somehow to move, so the user can see the rectangle moving...
View Replies
View Related
Sep 14, 2014
Following is the code on the click of a button, id like to know how do i close the current jframe on which the jButton4 is currently placed. I know how to send it to the next Jframe i.e JobCard. But need to close the current one. I tried using this.setVisible(true); But it does not work.
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
JobCard jobCard = new JobCard();
jobCard.setVisible(true);
}
View Replies
View Related
Mar 4, 2011
how the entire application could be close when you click on X in a JDialog Box. I have tried
System.Exit (0)
but it only close the Dialog box
View Replies
View Related
Sep 24, 2014
I didn't know about right method for correct close operation for JFrame component or kill the object. I found out few, which of them you are using usually???
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(false);
JFrame.DO_NOTHING_ON_CLOSE.
System.exit(0);
View Replies
View Related