• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:55
CET 14:55
KST 22:55
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners11Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation4Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
[TLMC] Fall/Winter 2025 Ladder Map Rotation Mech is the composition that needs teleportation t Weekly Cups (Nov 3-9): Clem Conquers in Canada Craziest Micro Moments Of All Time? SC: Evo Complete - Ranked Ladder OPEN ALPHA
Tourneys
Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament $5,000+ WardiTV 2025 Championship Merivale 8 Open - LAN - Stellar Fest
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle Terran 1:35 12 Gas Optimization BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET [ASL20] Grand Finals [Megathread] Daily Proleagues
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? Path of Exile Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread The Games Industry And ATVI
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1347 users

The Big Programming Thread - Page 818

Forum Index > General Forum
Post a Reply
Prev 1 816 817 818 819 820 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
December 19 2016 22:16 GMT
#16341
--- Nuked ---
Manit0u
Profile Blog Joined August 2004
Poland17429 Posts
Last Edited: 2016-12-20 16:00:00
December 20 2016 15:58 GMT
#16342
Holy crap! When did Rust get so much traction?

I remember that not so long ago people could barely compile anything in it and now dozens of big companies are using it for some critical parts of their operations. Mozilla is pretty big into it - not just taking it under its wings but also moving Firefox to it and developing new browser engine in it (to be released late 2017).

Videos posted by Mozilla Foundation show that some of their most senior devs consider it to be the new C++ but better.

Pretty amazing.
Time is precious. Waste it wisely.
RoomOfMush
Profile Joined March 2015
1296 Posts
December 20 2016 20:12 GMT
#16343
On December 21 2016 00:58 Manit0u wrote:
Holy crap! When did Rust get so much traction?

I remember that not so long ago people could barely compile anything in it and now dozens of big companies are using it for some critical parts of their operations. Mozilla is pretty big into it - not just taking it under its wings but also moving Firefox to it and developing new browser engine in it (to be released late 2017).

Videos posted by Mozilla Foundation show that some of their most senior devs consider it to be the new C++ but better.

Pretty amazing.

Although I really like many of the concepts of that language I absolutely hate the way it looks like. Its fugly in my opinion.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-12-21 01:02:39
December 21 2016 01:02 GMT
#16344
So I have absolutely no idea what I am doing but for some reason GUI in java is just incredibly confusing

All I want to do is draw a circle wherever I click on my jpanel.

Here is my code:

+ Show Spoiler +


import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class GraphGUI extends JPanel {

public static int x;
public static int y;

public static JFrame window = new JFrame();

/**
*
*/
private static final long serialVersionUID = 1L;

public void paintComponent(Graphics g) {
setSize(100, 100);
g.setColor(Color.red);
g.drawOval(x, y, 50, 50);
}

public GraphGUI() {

}

public static void main(String[] args) {
window.setSize(500, 500);
window.addMouseListener(m);
window.validate();
window.setVisible(true);

}

public static MouseListener m = new MouseListener() {

@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == 1) {
x = e.getX();
y = e.getY();

GraphGUI g = new GraphGUI();
window.add(g);
window.revalidate();
}

}

@Override
public void mouseEntered(MouseEvent e) {
}

@Override
public void mouseExited(MouseEvent e) {
}

@Override
public void mousePressed(MouseEvent e) {
}

@Override
public void mouseReleased(MouseEvent e) {
}
};

}




I have no idea what exactly validate and revalidate do. But I've figured out I need them. It's all very confusing.

I've figured out my problem here is: g.drawOval(x, y, 50, 50);

It's the x and y variables. For some reason paintComponent isn't using an updated x and y (it should change when mouseclick happens..).

I know this because if I write g.drawOval(50, 50, 50, 50) then there is no problem and it draws my circle at 50,50.
So that's cool and all but I want to draw the damn circle where I click the mouse. So how in the world do I do that?
Aerisky
Profile Blog Joined May 2012
United States12129 Posts
Last Edited: 2016-12-21 03:48:44
December 21 2016 03:48 GMT
#16345
I'm pretty rusty and haven't worked with a GUI in Java before, but on first glance, the paintComponent method takes x,y, which you never set for the GraphGui object. In the mouseClicked method, you set x and y, then create a new GraphGui object, but you haven't set that GraphGui object's x and y attributes, so paintComponent doesn't know what x and y are I think?
Jim while Johnny had had had had had had had; had had had had the better effect on the teacher.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
December 21 2016 04:17 GMT
#16346
I don't think that should matter because they are static so they are the only ones of those variables, and they already belong to GraphGUI.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-12-21 08:55:28
December 21 2016 04:53 GMT
#16347
Unspecific to your problem but I remember similar problems in my class when people first encountered GUIs (I did GUI programming previously) and I see a lot of weird code that means you'll eventually start building strange solutions on top of it. I have a *small* thing for GUIs lol.

You're doing a weird thing where you keep adding GraphGUI/JPanels inside your JFrame. This should be a memory leak but still bad practice. You should just be updating an existing GraphGUI (if you're doing it like that) by revalidating it. You shouldn't be referencing the static window like this. You can just add the GraphGUI to your JFrame once in the main function.

Use a Point2D class if you want to represent a point in space. This lets you be more descriptive.

You're calling setSize inside the paintComponent which generally makes no sense. paintComponent should just paint the component. The size of the GraphGUI should just be the size of your window here. You would attempt to resize the window every time it paints. Do the setSize once wherever you initialize the GraphGUI.

You shouldn't have a static MouseListener. The MouseListener should be in the GraphGUI/JPanel, added in its constructor. You can also use a MouseAdapter to not have the empty Overrides.

Your specific problem is that revalidating the outer window doesn't propogate the invalidation to its inner windows. GUI systems work the other way. When you invalidate inner windows the invalidation propogate upwards to its parents.

I believe you also also want to call repaint, not just revalidate. The terminology is confusing but they affect layout vs redraw.

Lmk if that fixes things.
There is no one like you in the universe.
Aerisky
Profile Blog Joined May 2012
United States12129 Posts
December 21 2016 04:55 GMT
#16348
Ah derp, I didn't see the indentation correctly at all haha, my bad.

Blisse seems like he knows what he's talking about here though >.<
Jim while Johnny had had had had had had had; had had had had the better effect on the teacher.
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
December 21 2016 09:10 GMT
#16349
@travis welcome to the garbage dump world called javax.swing.*
Age of Mythology forever!
RoomOfMush
Profile Joined March 2015
1296 Posts
December 21 2016 11:21 GMT
#16350
There are several things wrong with your code travis.
First of all, you are creating a new JPanel with each click and you try to add it to your JFrame. This is a really bad idea. By default the content pane of a JFrame is a JPanel with a BorderLayout. The BorderLayout can only take 5 components to lay out, after that I would assume it will crash but perhaps the error will be silently ignored.

The next problem is that your paintComponent method in your JPanel mutates (your setSize call) the JPanel itself which is illegal in Swing. You are also not running your application on the EDT (EventDispatcherThread) which you are supposed to do in Swing.

Here is a working example:
+ Show Spoiler +
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class ClickWindow {

public static void main(String[] args) {
// all Swing applications must be started this way to
// make sure the application runs on the EventDispatcherThread (EDT)
// if the application does not run on the EDT the behavior of
// Swing is not defined
EventQueue.invokeLater(() -> new ClickWindow());
}

private final JFrame frame = new JFrame();

public ClickWindow() {
// make sure the JVM ends when the frame is closed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// use some arbitrary size for testing
frame.setSize(640, 480);
// center the frame on screen
frame.setLocationRelativeTo(null);

// set our custom JPanel to be the content-pane (the root element) of our frame
frame.setContentPane(new ClickPanel());

// show the frame
frame.setVisible(true);
}

public static class ClickPanel extends JPanel {

private int x, y;

public ClickPanel() {
// A MouseAdapter is just an abstract class of MouseListener
// with empty implementations for all methods
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// we check for left-click
if (SwingUtilities.isLeftMouseButton(e)) {
// we take the X- and Y-coordinates from the event
x = e.getX();
y = e.getY();

// we need to repaint our ClickPanel
// when we want to draw a new dot
repaint();
}
}
});
}

public void paintComponent(Graphics g) {
// renders the border and background
super.paintComponent(g);
// renders our colored point
g.setColor(Color.RED);
g.drawOval(x, y, 50, 50);
}

}

}
RoomOfMush
Profile Joined March 2015
1296 Posts
December 21 2016 11:26 GMT
#16351
On December 21 2016 13:53 Blisse wrote:
You're doing a weird thing where you keep adding GraphGUI/JPanels inside your JFrame. This should be a memory leak but still bad practice.

There are no memory leaks in java (at least not at travis level). He is adding more components to his frame though and this WILL cause problems with his SceneGraph / GUI-Tree / DOM (whatever you want to call it in Swing).

On December 21 2016 13:53 Blisse wrote:
You should just be updating an existing GraphGUI (if you're doing it like that) by revalidating it.

Almost but not quite. Revalidating will do nothing in that case. What you want to do is repaint because the graphics have changed. Revalidation is only necessary when changing the GUI-Tree on the fly without using well-defined methods to do it. Its basically only needed when doing low-level manipulations. Even in that case an invalidate() is probably the better idea than a revalidate() but at that point even I get sometimes confused.
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
Last Edited: 2016-12-21 16:34:55
December 21 2016 16:32 GMT
#16352
this is a bit electronics related but since I have zero knowledge on it you guys may give me a start

my room is pretty far away from the door so often I can't hear the doorbell. Currently I'm abusing Skype to call from my cellphone near the door to my pc in my room when I am expecting someone. But it's not an optimal solution since it occupies my phone.

I borrowed a bare arduino uno from someone to fiddle with it. And found a simple project on the net that connects a mic to arduino, but it can only 'detect' a presence of sound, not transmit it.

what I need is a simplest circuit that can convert sound to analog signal to be supplied to arduino's analog inputs. From there I can figure out on my own the programming of arduino and a java program that will listen on my pc. All will run on lan
Age of Mythology forever!
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2016-12-21 17:16:48
December 21 2016 17:15 GMT
#16353
The generic tech for converting a digital signal to audio is a DAC, and to sound it's, well, it's called a speaker, but you probably already knew that. Here's a simple ish guide:

https://www.google.com/amp/www.instructables.com/id/Arduino-Basics-Making-Sound/?amp_page=true?client=ms-android-google


Ahh fucking AMP links sorry.

Let me know if I'm misunderstanding something about your question.
Who after all is today speaking about the destruction of the Armenians?
Cyx.
Profile Joined November 2010
Canada806 Posts
December 21 2016 18:48 GMT
#16354
On December 21 2016 00:58 Manit0u wrote:
Holy crap! When did Rust get so much traction?

I remember that not so long ago people could barely compile anything in it and now dozens of big companies are using it for some critical parts of their operations. Mozilla is pretty big into it - not just taking it under its wings but also moving Firefox to it and developing new browser engine in it (to be released late 2017).

Videos posted by Mozilla Foundation show that some of their most senior devs consider it to be the new C++ but better.

Pretty amazing.

Mozilla were the people who started Rust if I'm not mistaken, though it's a lot bigger than them now. I kind of agree with the people who think it's basically a better C++, in the sense that it fills the same systems-programming niche as C++ but in a much more modern and safer way. Though I haven't used it for anything serious at all so take that with a grain of salt.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-12-21 21:03:03
December 21 2016 20:39 GMT
#16355
On December 21 2016 20:26 RoomOfMush wrote:
Show nested quote +
On December 21 2016 13:53 Blisse wrote:
You're doing a weird thing where you keep adding GraphGUI/JPanels inside your JFrame. This should be a memory leak but still bad practice.

There are no memory leaks in java (at least not at travis level). He is adding more components to his frame though and this WILL cause problems with his SceneGraph / GUI-Tree / DOM (whatever you want to call it in Swing).

Show nested quote +
On December 21 2016 13:53 Blisse wrote:
You should just be updating an existing GraphGUI (if you're doing it like that) by revalidating it.

Almost but not quite. Revalidating will do nothing in that case. What you want to do is repaint because the graphics have changed. Revalidation is only necessary when changing the GUI-Tree on the fly without using well-defined methods to do it. Its basically only needed when doing low-level manipulations. Even in that case an invalidate() is probably the better idea than a revalidate() but at that point even I get sometimes confused.


Yeah I kind of mixed up "memory leak" with "continually adding useless objects to the tree". Also I realized my mistake at the end of the post but didn't fix the mistake in the middle. :D

Totally untested code and not to standards like mush

+ Show Spoiler +


public class GraphGUI extends JPanel {

private Point circleLocation = null;

@Override
public void paintComponent(Graphics g) {
if (circleLocation != null) {
g.setColor(Color.red);
g.drawOval(circleLocation.x, circleLocation.y, 50, 50);
}
}

public GraphGUI() {
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == 1) {
circleLocation = new Point(e.getX(), e.getY());
repaint();
}
}
})
}

public static void main(String[] args) {
JFrame window = new JFrame();
window.setSize(500, 500);
window.setVisible(true);
window.add(new GraphGUI());
window.revalidate();
}
}

There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-12-21 21:49:43
December 21 2016 20:51 GMT
#16356
wow thanks guys

and mush, that tutorial was very clear, thank you so much.
the one thing in it I have questions about though is paintComponent and Graphics.

So, I believe paintComponent is a method that components have that we are overriding here to specify what it should do
But what is Graphics? Is it just some parameter that repaint is passing to paintComponent behind the scenes? What is the point of Graphics?

Like, why doesn't paintComponent look like this: (i know this doesn't work, I just don't understand what the role of Graphics is)


public void paintComponent() {
this.setColor(blah blah)
this.drawOval(blah blah)
}
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
December 21 2016 21:04 GMT
#16357
On December 22 2016 02:15 phar wrote:
The generic tech for converting a digital signal to audio is a DAC, and to sound it's, well, it's called a speaker, but you probably already knew that. Here's a simple ish guide:

https://www.google.com/amp/www.instructables.com/id/Arduino-Basics-Making-Sound/?amp_page=true?client=ms-android-google


Ahh fucking AMP links sorry.

Let me know if I'm misunderstanding something about your question.


noo noo I won't be making sound using arduino

it will be like this

microphone circuit sends analog signal to arduino
arduino processes it if necessary and sends data over lan to my pc
a program on my pc will play the sound

I'm only asking about the first part (listening to sound). Rest I can figure out.
Age of Mythology forever!
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2016-12-21 21:30:43
December 21 2016 21:28 GMT
#16358
On December 22 2016 05:51 travis wrote:
wow thanks guys

and mush, that tutorial was very clear, thank you so much.
the one thing in it I have questions about though is paintComponent and Graphics.

So, I believe paintComponent is a method that components have that we are overriding here to specify what it should do
But what is Graphics? Is it just some parameter that repaint is passing to paintComponent behind the scenes? What is the point of Graphics?

Like, why doesn't paintComponent look like this: (i know this doesn't work, I just don't understand what the role of Graphics is)

public void paintComponent() {
this.setColor(blah blah)
this.drawOval(blah blah)
}

Graphics is an interface used to render all kinds of graphics to screen. There can be different implementations of graphics which could even be implemented with native code; perhaps in C or C++. Conceptually a Graphics object is similar to an OpenGL context. It saves state like clipping, colors, blend modes, etc and offers methods of drawing primitive shapes or text.

In Swing each component can call the repaint() method which will notify the EventDispatcherThread (EDT) that the component would like to be repainted. The EDT will then, at some point in the near future, call the paintComponent method of the component and pass a valid Graphics object for the parameter. The paintComponent method is not necessarily called once for every call to repaint. Its perfectly possible (and generally the case), that the EDT will ignore successive calls to repaint() before paintComponent has been called. How the Graphics object is constructed, whether its always the same, whether different Components will get the different Graphics objects or not, etc are implementation details that you should not care about. They may differ in future versions of Swing (although it is highly unlikely that Swing will ever get any major updates since JavaFX was just released).

In general you should never save the Graphics object you get in paintComponent in an attribute. You should also never use the Graphics object outside of the paintComponent method for that particular component. Consider it to be temporary and only used within that one painting action.

There is also an option of doing the usual while-true loop and rendering to the graphics context directly if you prefer the old-school style. You will lose much of Swings functionality if you do this though.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
December 21 2016 21:36 GMT
#16359
So what I want to do now is paint a new circle at each spot i click, but keep the old ones too.

Is the best way to do that to save my x and y coordinates into a 2d array, and then iterate through them in paintComponent to paint all the circles? (seems a bit awkward).

RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2016-12-21 21:43:54
December 21 2016 21:39 GMT
#16360
On December 22 2016 05:39 Blisse wrote:
Show nested quote +
On December 21 2016 20:26 RoomOfMush wrote:
On December 21 2016 13:53 Blisse wrote:
You're doing a weird thing where you keep adding GraphGUI/JPanels inside your JFrame. This should be a memory leak but still bad practice.

There are no memory leaks in java (at least not at travis level). He is adding more components to his frame though and this WILL cause problems with his SceneGraph / GUI-Tree / DOM (whatever you want to call it in Swing).

On December 21 2016 13:53 Blisse wrote:
You should just be updating an existing GraphGUI (if you're doing it like that) by revalidating it.

Almost but not quite. Revalidating will do nothing in that case. What you want to do is repaint because the graphics have changed. Revalidation is only necessary when changing the GUI-Tree on the fly without using well-defined methods to do it. Its basically only needed when doing low-level manipulations. Even in that case an invalidate() is probably the better idea than a revalidate() but at that point even I get sometimes confused.


Yeah I kind of mixed up "memory leak" with "continually adding useless objects to the tree". Also I realized my mistake at the end of the post but didn't fix the mistake in the middle. :D

Totally untested code and not to standards like mush

+ Show Spoiler +


public class GraphGUI extends JPanel {

private Point circleLocation = null;

@Override
public void paintComponent(Graphics g) {
if (circleLocation != null) {
g.setColor(Color.red);
g.drawOval(circleLocation.x, circleLocation.y, 50, 50);
}
}

public GraphGUI() {
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == 1) {
circleLocation = new Point(e.getX(), e.getY());
repaint();
}
}
})
}

public static void main(String[] args) {
JFrame window = new JFrame();
window.setSize(500, 500);
window.setVisible(true);
window.add(new GraphGUI());
window.revalidate();
}
}


A few suggestions:

Instead of doing:
circleLocation = new Point(e.getX(), e.getY());

you can do:
circleLocation = e.getPoint();


I would highly recommend doing:
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

after creating your JFrame. The default value is JFrame.HIDE_ON_CLOSE which will not dispose the frame and not end any timers. This can turn out really bad when your JVM keeps running in the background without any visible frames. In that situation you would need to kill the process manually to end the program.

The call to
window.setVisible(true);

should also be the very last thing you do in your code. If you do it this way you will never need to pack, validate, revalidate or invalidate your JFrame. The frame will automatically validate when it is set to visible.

Instead of adding teh GraphGUI to your frame you can also set it to be the contentPane of the frame. The add-method will simply add your new JPanel to the current contentPane which means you have 2 panels but only one is really used.


And remember to start Swing on the EventDispatcherThread (EDT) in your main-method. If you dont do it you will eventually run into BIG trouble when developing a larger application. I didnt do it once and I ran into random bugs that could never be reproduced but kept happening every now and then. It was usually graphical glitches or lost inputs. I later found out that I didnt run the application on the EDT and the errors were due to undefined behavior of Swing when not running on the EDT. You certainly dont want that to happen in later stages of developement.

On December 22 2016 06:36 travis wrote:
So what I want to do now is paint a new circle at each spot i click, but keep the old ones too.

Is the best way to do that to save my x and y coordinates into a 2d array, and then iterate through them in paintComponent to paint all the circles? (seems a bit awkward).


Dont use an array, use an ArrayList instead since it will automatically resize as needed. The iterating in paintComponent is the correct thing to do.
Prev 1 816 817 818 819 820 1032 Next
Please log in or register to reply.
Live Events Refresh
Kung Fu Cup
12:00
2025 Monthly #3: Day 1
Reynor vs GuMihoLIVE!
ByuN vs ShoWTimE
RotterdaM523
TKL 182
Rex146
IntoTheiNu 103
SteadfastSC88
Liquipedia
OSC
11:30
Mid Season Playoffs
Cure vs SpiritLIVE!
Krystianer vs Percival
WardiTV446
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 523
Reynor 227
TKL 182
Rex 146
SteadfastSC 88
StarCraft: Brood War
Calm 4495
Rain 2923
Bisu 2701
Hyuk 2015
Horang2 1304
Flash 797
Soma 464
Backho 369
Stork 340
Rush 261
[ Show more ]
Pusan 197
Last 133
Soulkey 115
JulyZerg 104
Barracks 79
hero 58
sSak 33
zelot 31
Aegong 28
sas.Sziky 24
Killer 23
Terrorterran 11
Noble 9
Hm[arnc] 7
Dota 2
Gorgc2155
qojqva1591
Dendi1136
XcaliburYe181
BananaSlamJamma86
Counter-Strike
olofmeister911
allub158
Super Smash Bros
Mew2King127
Other Games
B2W.Neo990
hiko295
DeMusliM285
Pyrionflax260
Sick170
Fuzer 164
Hui .86
QueenE46
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Adnapsc2 9
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 1641
• WagamamaTV400
League of Legends
• Nemesis1689
• TFBlade702
Upcoming Events
Tenacious Turtle Tussle
9h 5m
The PondCast
20h 5m
RSL Revival
20h 5m
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
22h 5m
WardiTV Korean Royale
22h 5m
PiGosaur Monday
1d 11h
RSL Revival
1d 20h
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
1d 22h
CranKy Ducklings
2 days
RSL Revival
2 days
herO vs Gerald
ByuN vs SHIN
[ Show More ]
Kung Fu Cup
2 days
IPSL
3 days
ZZZero vs rasowy
Napoleon vs KameZerg
BSL 21
3 days
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
3 days
RSL Revival
3 days
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
3 days
WardiTV Korean Royale
3 days
BSL 21
4 days
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
4 days
Dewalt vs WolFix
eOnzErG vs Bonyth
Wardi Open
4 days
Monday Night Weeklies
5 days
WardiTV Korean Royale
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2025-11-07
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.