[Solved] Java: Delete a file starting with “.” [duplicate]

Use the nio package instead : import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; Path p = Paths.get(“/tmp/.minecraft”); if(!Files.exists(p)){ Files.createFile(p); } if(Files.exists(p)){ Files.delete(p); } 10 solved Java: Delete a file starting with “.” [duplicate]

[Solved] The image’s event handler shows error in Java GUI

Why are you creating new instance of JButton in roll? You just need to change the icon of the buttons which are already displayed on the screen This… public void roll() { value = nextValue() ; if (value==1){ Icon i=new ImageIcon(getClass().getResource(“1.png”)); c= new JButton(i); add(c); } else if(value==2){ Icon im=new ImageIcon(getClass().getResource(“2.png”)); c= new JButton(im); add(c); … Read more

[Solved] make application with database MySQL is faster [closed]

For db Add indexes for frequently searched fields Think about table partitioning, rarely searched data should be stored in archive tables For backend Optimize queries Minimize cursor fetching For client Use pagination to avoid large data loading Use async loading (SwingWorker for swing, Service for javafx) to avoid UI hanging Don’t mix archive and working … Read more

[Solved] how to output a user selected shape & color, whose location and dimensions depend upon the coordinate location of user clicks

The following is a suggested implementation, also incorporating the good guidance you got from Frakcool: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Point; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; import java.util.HashMap; import java.util.Map; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JToggleButton; … Read more

[Solved] How to know what r,g,b values to use for get other colours to paint a JFrame dynamically?

Your current approach is indeed not easily generalizable. The hard-coded parts of the buttons for “blue” and “green”, and especially the special methods like blueToGreen make it impossible to extend the number of colors with reasonable effort. (You don’t want to create methods blueToYellow, blueToRed, blueToTheThirdColorFromThisListForWhichIDontKnowAName …). There are many possible ways of generalizing this. … Read more

[Solved] Trying to add an event listener to a JTextField

Since you edited the question and clarified that you are using a JTextField I will reorder the answer: You don’t see any output because the action command has not been set so there is nothing to display. Try using the following in your ActionListener: JTextField textField = (JTextField)e.getSource(); System.out.println( textField.getText() ); Of course this will … Read more

[Solved] How can I use Program a game after swing.Timer stopped?

Your problem is that you don’t use correct architecture pattern. You should separate your business logic from your presentation. Also you should store variables (like time_left) in model, not in the controller (i.e. ActionListener). Please read about: Model View Controller pattern. It’s a basic pattern and it’ll solve most of yours problems. Basic Example Editor.java … Read more

[Solved] Is there an “onChange” for Java? [closed]

There is no generic onChange function. However there is a method you can define in a class that implements KeyListener which is public void keyPress. You would use this something like the following: public class MyClass implements KeyListener { private JTextField myField; private JLabel myLabel; public MyClass() { myLabel = new JLabel(“Enter text here”); myField … Read more