jframe

Downloading file/files in Java. Multithreading, this works?

十年热恋 提交于 2019-12-02 11:14:21
问题 First, everyone needs to know i'm relatively new to Java coding. To be more precise i'm completely new to Object Oriented Programming. To the question. I am trying to create a download class that updates a progress bar it was given to show its progress. And possibly anything else I decide to give it in the future to update. The issue currently is that, in my head, this shouldn't work. I can do anything i want on the "main" method and the GUI is still responsive and quick. In my experience in

How to add jzy3d chart to JFrame without making a new one?

隐身守侯 提交于 2019-12-02 10:59:43
问题 There is the following code for making jzy3d chart in JFrame: public class SurfaceViewerFrame extends IconFrame { public SurfaceViewerFrame() { setResizable(false); //System.loadLibrary("lib/jogl2-rc10/gluegen-rt.jar"); Settings.getInstance().setHardwareAccelerated(true); FormLayout layout=new FormLayout("10px, 300px, 10px", "30px, 10px, 20px, 300px, 10px"); CellConstraints сс=new CellConstraints(); JLabel title=new JLabel("Выходная поверхность"); Mapper mapper = new Mapper() { public double

java.lang.IllegalArgumentException: adding a window to a container

戏子无情 提交于 2019-12-02 10:53:29
I get 'java.lang.IllegalArgumentException: adding a window to a container' when I call frame.add(this). What am I doing wrong, and how do I fix the error. Thanks in advance. public class mainclass extends JFrame{ private static final long serialVersionUID = 1L; private int width = 400; private int height = 400; public static JFrame frame; public static void main(String args[]) { frame = new JFrame(); mainclass mainclass = new mainclass(); mainclass.createFrame(); } public void createFrame() { frame.setSize(new Dimension(width, height)); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.add

Add components directly to JFrame, or put them inside a JPanel?

依然范特西╮ 提交于 2019-12-02 10:36:33
问题 I have a general question regarding java GUI. If I have several components that I want to add to a JFrame, should i put them directly inside the JFrame, or add them to a JPanel, and then add the panel to the frame? If adding the components to a JPanel first is the best, why? I usually do this, then I understood that I have no idea why/if this is more optional then adding directly to the frame. JFrame also have layout managers, so it's possible to get them in the correct position. 回答1: When

Java Painting not working

陌路散爱 提交于 2019-12-02 10:24:27
So I have this code: package tictactoe; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class TicTacToe extends JFrame { public static void main(String[] args) { JFrame masterFrame = new JFrame("TicTacToe"); JPanel drawingPanel = new JPanel(); GameBoard theGame = new GameBoard(); masterFrame.add(drawingPanel); masterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); masterFrame.setSize(504, 504); masterFrame.setResizable(false); masterFrame.setLocationRelativeTo(null); masterFrame.setVisible(true); } //End of Main method

garbage collector for JFrame's object

◇◆丶佛笑我妖孽 提交于 2019-12-02 10:20:26
问题 import javax.swing.*; public class Main { public Main() { JFrame jf = new JFrame("Demo"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(100, 100); jf.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Main(); } }); Runtime.getRuntime().gc(); } } I call Runtime.getRuntime().gc(); for explicit garbage collector invoking. But window doesn't dissapear from screen, why doesn't garbage collector

How to update Java Jframe controls from no-gui class on real time

こ雲淡風輕ζ 提交于 2019-12-02 10:17:27
I have a tedious problem with my Java JFrame project. What I want to do (and looking for how to) is add elements to my ListBox from a no-GUI class in REAL TIME, or in other words "asynchronous", with out freezing my app. Is this clear? I tried SwingWorker and Threads but without results. All I can do is update the listbox after all process finish (obviously with my app froze because my process is long). This is my architecture: And here is my code (not functional, just for understanding) EDITTED View (Generated with NetBeans) package view; import com.everis.ingesta.controller.MyController;

How to properly refresh image in JFrame?

不羁的心 提交于 2019-12-02 10:06:55
This is a problem that disturbs me for few hours now and I'm not able to find a solution by myself... I've found similar topics all around the net, but I couldn't find exact same problem with well explained and as simple as possible solution. I've also looked at EDT and SwingWorker API docs, but it was far too complicated for me :( So, let's get to the point. I have a simple JFrame with JLabel inside, that consist of my image: private static class MyJLabel extends JLabel { private ImageIcon img = null; public MyJLabel(ImageIcon img) { super(); this.img = img; } @Override public void

Java Scanner issues (JFrame)

£可爱£侵袭症+ 提交于 2019-12-02 10:01:33
I am trying to use a scanner to edit the level of my tower defense game. However it will not update the level (the tile images) to that of the custom file (0 is grass 1 is stone -1 is nothing, etc.). I have found the error but how do i fix it, what do i need to add/change to get rid of this? java.lang.NullPointerException at Levels.loadLevels(Levels.java:11) at Window.define(Window.java:28) at Window.paintComponent(Window.java:44) line 11: for(int y=0;y<Window.room.block.length;y++) { line 28: levels.loadLevels(new File("levels/level1.level")); line 44: define(); This is the scanner file:

can't draw on JFrame

风格不统一 提交于 2019-12-02 09:56:00
I'm trying to make a simle java program that draws a circle at the mouse localization, it gets the mouse X and Y coordinates but it doesn't draw anything, i tried to draw a String, a circle and a line but nothing worked, i changed the code a bit but it still doesn't works class Test4 { public static String a; public static JFrame frame = new JFrame(); public static Point Gett(){ PointerInfo h = MouseInfo.getPointerInfo(); Point b = h.getLocation(); return b; } public void paintComponent(int x, int y, Graphics g) { g.drawOval(x, y, 10, 10); } public static void main(String[] args) throws