• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:35
CEST 03:35
KST 10:35
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)36Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) [D] Wireframe Casting Removed Clem: "I don't have that much hope in Blizzard" Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken?
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
Etiquete rules in Asl? BW General Discussion Recent recommended BW games Recommended FPV games (post-KeSPA) Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map)
Tourneys
Escore Tournament - Season 3 Small VOD Thread 2.0 [IPSL] Spring 2026 Grand Finals - This Weekend! [Megathread] Daily Proleagues
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
General RTS Discussion Thread Path of Exile Nintendo Switch Thread Beyond All Reason Stormgate/Frost Giant Megathread
Dota 2
Looking for a Dota Mentor 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
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread The Games Industry And ATVI Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7780 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
Poland17794 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
Turkey781 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
Turkey781 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
Turkey781 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
Replay Cast
00:00
Crank Gathers S4: Group Stage
CranKy Ducklings70
LiquipediaDiscussion
PSISTORM Gaming Misc
23:00
FSL playoffsTeamLeague STvsASH
Liquipedia
The PiG Daily
22:00
Best Games of SC
ByuN vs Clem
MaxPax vs TBD
Serral vs ByuN
GgMaChine vs Bunny
PiGStarcraft569
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft569
ViBE255
RuFF_SC2 78
FoxeR 42
StarCraft: Brood War
Leta 1279
Mong 122
NaDa 34
Dota 2
NeuroSwarm171
Counter-Strike
summit1g7900
taco 190
Super Smash Bros
Mew2King310
Heroes of the Storm
Trikslyr71
Other Games
gofns10805
tarik_tv4592
shahzam908
ToD113
XaKoH 105
PPMD20
Organizations
Other Games
gamesdonequick1798
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 66
• davetesta26
• RyuSc2 26
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Pr0nogo 3
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Shiphtur640
Upcoming Events
RSL Revival
7h 25m
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
8h 25m
Epic.LAN
11h 25m
IPSL
14h 25m
Dragon vs Hawk
RSL Revival
1d 7h
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
1d 8h
OSC
1d 11h
IPSL
1d 14h
Bonyth vs Ret
WardiTV Weekly
2 days
Monday Night Weeklies
2 days
[ Show More ]
PiGosaur Cup
3 days
The PondCast
4 days
Replay Cast
5 days
CrankTV Team League
5 days
Replay Cast
5 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Escore Tournament S3: W3
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
YSL S3
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
ASL S22 SEASON OPEN Day 1
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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 © 2026 TLnet. All Rights Reserved.