swing

Java Jframe get input and write to file [duplicate]

懵懂的女人 提交于 2021-02-05 12:19:24
问题 This question already has answers here : How to append text to an existing file in Java? (31 answers) Closed 3 years ago . I have one project that I want to get input from jframe. I have to input 3 people data in only one time when code was running and write that data into file name person.txt.Those data have Name Nickname Age and when i compile my code, It dosn't work and I just only write one data in person.txt file. Help me please? I can't get those in my project. what should i do ? public

java set delay to change imageicon

一曲冷凌霜 提交于 2021-02-05 12:18:57
问题 i'm trying to set a delay when a button is pressed to set an imageicon to a certain image then set another delay so that another image would be set, all of this by single click. in other word : click a button->set image->delay->set another image. what i get in my code is the last state only "set another image". also i don't want to use use timers, i want to use delays. and here the part in my code i'm concerned about. btnNewButton.addMouseListener(new MouseAdapter() { @Override public void

JFrame doesn't take the actual screen size

浪子不回头ぞ 提交于 2021-02-05 11:56:18
问题 I have been trying to set the size of my JFrame to the exact same size of my screen (2256x1504). It also seems to take that size but when I display something the outcome is always bigger than intended. public class Frame extends JFrame { public Frame() { JPanel p = new JPanel(); int width = 2256; int height = 1504; Dimension size = new Dimension(width,height); p.setPreferredSize(size); p.setMinimumSize(size); p.setMaximumSize(size); p.setSize(size); this.setUndecorated(true); this

automatic update jtextfield

最后都变了- 提交于 2021-02-05 11:37:55
问题 Does anyone know how to update a jTextfield every 5 secondes? Automatic. So no userinput is required. It is used to update time in a textfield. This is what i tried but then my program freezes. while(true){ Thread.sleep(1000); txtCheck.setText(convert.getCheck()); System.out.println("Ja"); } convert is a thread, i tried to throw an exception but failed, cause Eclise says Threads can't throw exceptions. Convert.getCheck: public String getCheck() { return check; } 回答1: You want to use a Swing

How to resize an Image depending on the size of JLabel when the user select rows in database

孤者浪人 提交于 2021-02-05 11:29:07
问题 I have a system where user can input pictures on it and I already search online on how to resize an image according to the size of JLabel and it works. However when i click other picture on JTable(database), it somehow gets back to its normal size and not resizing to the JLabel anymore. How would I fix this? This is the code for the Upload Button private void btnUploadActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(null);

Java Graphics not showing on Mac even with overriding the paintComponent() method of the JPanel

和自甴很熟 提交于 2021-02-05 11:21:05
问题 I'm working on a small game project and am having an issue with java graphics not being displayed. I've searched similar questions here on Stackoverflow and used overriding the paintComponent() method of the JPanel which many ppl advised but am still having this issue. I hope to get my background image and menubar, and music at the same time. Music works fine but background image and menubar doesn't show up at all. here's my code : import java.awt.Graphics; import java.awt.Image; import javax

Add Jbutton to Jpanel

给你一囗甜甜゛ 提交于 2021-02-05 11:13:30
问题 can somebody tell me what is wrong with this code i am trying to add the buttons to my JPanel ArrayList<JButton> buttons = new ArrayList<JButton>(); JPanel createButtonspane(){ bpanel = new JPanel(); for(int i=0; i<10; i++){ buttons.add(new JButton(""+i)); bpanel.add(buttons); } return bpanel; } 回答1: This code does not compile because JPanel does not have an overload of add() which takes an array of JButton s, so you can not add a whole array of buttons to the JPanel (even if it was possible,

Java Drawing Multiple Squares in Same JFrame

橙三吉。 提交于 2021-02-05 11:12:05
问题 I am trying to make an animation with multiple thread. I want to paint n squares where this n comes from commend-line argument. Every square has their x-y coordinates, colors and speed. They are moving to the right of the frame with different speed, color and coordinates. Since I am using multi thread I assume I have to control each squares. So I have to store each square object in the ArrayList. However, I am having trouble with painting those squares. I can paint one square but when I try

Add Jbutton to Jpanel

可紊 提交于 2021-02-05 11:10:16
问题 can somebody tell me what is wrong with this code i am trying to add the buttons to my JPanel ArrayList<JButton> buttons = new ArrayList<JButton>(); JPanel createButtonspane(){ bpanel = new JPanel(); for(int i=0; i<10; i++){ buttons.add(new JButton(""+i)); bpanel.add(buttons); } return bpanel; } 回答1: This code does not compile because JPanel does not have an overload of add() which takes an array of JButton s, so you can not add a whole array of buttons to the JPanel (even if it was possible,

Java Drawing Multiple Squares in Same JFrame

*爱你&永不变心* 提交于 2021-02-05 11:04:02
问题 I am trying to make an animation with multiple thread. I want to paint n squares where this n comes from commend-line argument. Every square has their x-y coordinates, colors and speed. They are moving to the right of the frame with different speed, color and coordinates. Since I am using multi thread I assume I have to control each squares. So I have to store each square object in the ArrayList. However, I am having trouble with painting those squares. I can paint one square but when I try