swing

Listing objects in ArrayList in GUI and alternating between many ArrayLists

让人想犯罪 __ 提交于 2021-02-11 16:46:47
问题 I'm currently working on a personal project, in this project, the user is asked to create objects under 3 different categories, so after the object is created, there's a method that check's the category of the object and then it adds it to an ArrayList. More Details: the object is called Vehicle, there're three categories: Two wheels, three weels, three wheels. So, when you create a new Vehicle, you'd be asked to specify what kind of vehicles you're creating, say you said two wheels, a method

How to add a paintComponent() to a JPanel

白昼怎懂夜的黑 提交于 2021-02-11 15:14:49
问题 I have 2 classes, Class2 and Class4. I wish to add the paint in Class2 from Class4 onto a JPanel in Class4 using the p4.add(c2o) and f.add(p4) methods. I have no problems adding GUI but I simply couldn't add graphics. Class4: import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class Class4 { public void mainMethod(int event){ JFrame f = new JFrame("Love Test"); if(event == 0){ f.setDefaultCloseOperation(JFrame.EXIT_ON

Java: Updating UI while waiting for another thread to finish

匆匆过客 提交于 2021-02-11 15:05:59
问题 I have some Java Swing login panel. When user click "login" button, extensive DB communication takes place. I got an idea to put that db communication into another thread (that db communication is used for filling some hash maps and singletons). After putting that communication into separate thread, db heavy lifting takes place while user is typing it's uname and password. When user clicks "login" button, than code will wait for "heavy lifting" thread to join, and then proceed. The problem is

Java: Updating UI while waiting for another thread to finish

不打扰是莪最后的温柔 提交于 2021-02-11 15:01:35
问题 I have some Java Swing login panel. When user click "login" button, extensive DB communication takes place. I got an idea to put that db communication into another thread (that db communication is used for filling some hash maps and singletons). After putting that communication into separate thread, db heavy lifting takes place while user is typing it's uname and password. When user clicks "login" button, than code will wait for "heavy lifting" thread to join, and then proceed. The problem is

Java Snake Game: Apple showing while snake is invisible

北战南征 提交于 2021-02-11 14:51:04
问题 I am following a the following video to design a snake game: https://www.youtube.com/watch?v=91a7ceECNTc I am following it step by step, but when I run it, the snake does not show on my screen, just the apple. I think I have something wrong when implementing public void paint(Graphics g); Can someone help me? This is the code my Main class import javax.swing.JFrame; public class Main { public static void main(String[] args) { JFrame frame = new JFrame (); GamePanel panel = new GamePanel();

Java Snake Game: Apple showing while snake is invisible

余生长醉 提交于 2021-02-11 14:50:29
问题 I am following a the following video to design a snake game: https://www.youtube.com/watch?v=91a7ceECNTc I am following it step by step, but when I run it, the snake does not show on my screen, just the apple. I think I have something wrong when implementing public void paint(Graphics g); Can someone help me? This is the code my Main class import javax.swing.JFrame; public class Main { public static void main(String[] args) { JFrame frame = new JFrame (); GamePanel panel = new GamePanel();

Enter value in JTable cell and click OK does not register value

▼魔方 西西 提交于 2021-02-11 14:11:53
问题 I have a JTable which has certain cells editable. If the user enters in a value into an editable cell and then clicks the OK button on my form, the code: // Get the value in the editable cell String value = model.getValueAt(row, column); does not pick up the entered value. The only way the entered value is picked up by the above code is once the user has pressed enter after typing in the value or clicking in another cell for the value to be "pushed in". Does someone know what code I could

Calibri Font when in <html> text moves to the bottom part of the component

只谈情不闲聊 提交于 2021-02-11 14:00:28
问题 There is not a lot to explain. Just see the MCVE/image below: public class FontExample extends JFrame { private static final Font FONT = new Font("Calibri", Font.PLAIN, 14); public FontExample() { super(""); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new FlowLayout()); JLabel withoutHtml = new JLabel("hello stackoverflow"); withoutHtml.setFont(FONT); withoutHtml.setBorder(BorderFactory.createLineBorder(Color.red)); add(withoutHtml); JLabel withHtml = new JLabel("<html><body

Java, changing boolean column to checkbox in jTable when using rs2xml for populating jTable

时光总嘲笑我的痴心妄想 提交于 2021-02-11 13:36:51
问题 I am using a jTable which is populated with mysql db data using rs2xml table.setModel(DbUtils.resultSetToTableModel(rs)); I have some columns that are displayed by boolean values, but these must become checkboxes. I understand that i have to write my own AbstractTableModel, but I don't know how... Can one of you give an example of how you extend the AbstractTableModel and use it in your code? 回答1: I have some columns that are displayed by boolean values, but these must become checkboxes. Then

Updating a List<Point> on componentResized event

寵の児 提交于 2021-02-11 12:54:47
问题 I have a JInternalFrame that I draw on with Graphics2D. Each Graphics2D object is drawn in a location based on a java.util.List. I am interested in updating the location of the points on a componentResized event and then repaint the Graphics2D objects, in effect scaling with the window, but I cannot figure out how to do it. I tried overloading the componentResized to get the new window size and add to the points in the list but this isn't working. EDIT: After some help (alright a lot of help)