15,895,746 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by naeemashfaq (Top 4 by date)
naeemashfaq
4-Oct-12 13:47pm
View
I got it from the internet. I am really grateful to you for giving me your time.
I tried your code but it also overwrites the 1st object. When I tried the different layouts of JFrame, it shows both objects but the second object disappears after 2 or 3 seconds. I am copying the code.
public class DrawRect extends JFrame{
public static void main(String[] args)
{
JFrame f = new JFrame();
Ballbewegung ball = new Ballbewegung(10,100);
Ballbewegung ball1 = new Ballbewegung(15,300);
f.getContentPane().add(ball, BorderLayout.CENTER);
f.getContentPane().add(ball1, BorderLayout.WEST);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(600, 500);
f.setVisible(true);
}
}
naeemashfaq
4-Oct-12 6:56am
View
This is my class that creates a circle shape with specific x and y coordinates. Similarly I have another same class but with different x and y coordinate positions. I create 1 object of each class and want to display them on specific positions. I tried the code, it works well with your example but not working with my classes.
class Ballbewegung2 extends JPanel implements Runnable
{
// Initialisierung der Variablen
int x_pos = 10; // x - Position des Balles
int y_pos = 100; // y - Position des Balles
int radius = 20; // Radius des Balles
public void init()
{
setBackground (Color.blue);
}
public void start ()
{
Thread th = new Thread (this);
th.start ();
}
public void run ()
{
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (true)
{
x_pos ++;
if(x_pos >= 400)
x_pos = 10;
repaint();
try
{
Thread.sleep (20);
}
catch (InterruptedException ex)
{}
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
public void paint (Graphics g)
{
g.setColor (Color.red);
g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
}
}
naeemashfaq
3-Oct-12 15:57pm
View
I am from Sweden. I am new to Java programming. I am using the same Border Layout but the coordinates where I am displaying the objects are different. I tried this code but it also shows last object. My classes are extending JPanel.then how can I show both objects?
naeemashfaq
3-Oct-12 15:10pm
View
Thanks for replying. How can I have direct extension to Jpanel? I have also tried with default layout but all in vain. I am also unable to view the code