i have a menu bar, when i run the code the first time everything is fine. If i click on the screen i print a Circle or a Square, store the shape in an arraylist and repaint the frame. When the frame repaints the menuBar gets painted again under the orignal.
Any ideas? -
public class X2Frame extends JFrame {
-
private JMenuBar menuBar = new JMenuBar();
-
private JMenu menuTool = new JMenu();
-
private JMenuItem menuToolSquare = new JMenuItem();
-
private JMenuItem menuToolCircle = new JMenuItem();
-
private BorderLayout borderLayout1 = new BorderLayout();
-
private CanvasPanel canvasPanel = new CanvasPanel();
-
-
public X2Frame() {
-
try {
-
jbInit();
-
} catch (Exception e) {
-
e.printStackTrace();
-
}
-
}
-
-
private void jbInit() throws Exception {
-
this.setJMenuBar( menuBar );
-
this.getContentPane().setLayout(borderLayout1);
-
this.setSize( new Dimension(400, 300) );
-
menuTool.setText("Tool");
-
menuTool.setMnemonic('T');
-
menuToolSquare.setText("Square");
-
menuToolSquare.setMnemonic('S');
-
menuToolSquare.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) {
-
menuToolSquare_ActionPerformed(e);
-
} } );
-
menuToolCircle.setText("Circle");
-
menuToolCircle.setMnemonic('C');
-
menuToolCircle.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
menuToolCircle_actionPerformed(e);
-
}
-
});
-
menuTool.add( menuToolSquare );
-
menuTool.add(menuToolCircle);
-
menuBar.add(menuTool);
-
this.getContentPane().add(canvasPanel, BorderLayout.CENTER);
-
}
-
21 1637
Ahhh!!! so you are using JDeveloper ...am i right?
What jdk did you use?
it is recommended that you use jdk 5.0.... try it again, and update us....
sukatoa
Whats a JDK, and how do i change it?
Update to problem:
Not only is the menubar being repainted, but if i draw a square, then change tools and draw something else, the first square and the menubar gets doubled directly under the first. If i resize the window it goes back to normal. Paint again and it doubles again.
Whats a JDK, and how do i change it?
You can download it at Sun Microsystems... .
jdk(Java development kit) 5.0.... i can't remember the procedure... that was last 3 month's ago when i tried to use it.... but seems, the code generator fail sometimes....
I prefer to use netbeans if making GUI in a hurry.....
So, i came back to JCreator Lite....
I like to test your code, can you post the whole code?
sukatoa...
its split up in 6 classes,
not sure that posting it is the easiest way. -
import java.awt.Graphics2D;
-
import java.awt.geom.Ellipse2D;
-
-
public class Circle extends Shape {
-
-
public Circle(int x, int y) {
-
super.setX(x);
-
super.setY(y);
-
}
-
public void draw( Graphics2D g2 )
-
{
-
int CircleX = super.getX() - (super.SHAPE_WIDTH/2);
-
int CircleY = super.getY() - (super.SHAPE_WIDTH/2);
-
//Problem Area
-
Ellipse2D.Double circle = new Ellipse2D.Double(CircleX,CircleY,super.SHAPE_WIDTH,super.SHAPE_WIDTH);
-
g2.draw(circle);
-
}
-
}
-
-
import java.awt.BorderLayout;
-
import java.awt.Dimension;
-
import java.awt.event.ActionEvent;
-
import java.awt.event.ActionListener;
-
-
import javax.swing.JFrame;
-
import javax.swing.JMenu;
-
import javax.swing.JMenuBar;
-
import javax.swing.JMenuItem;
-
-
public class X2Frame extends JFrame {
-
private JMenuBar menuBar = new JMenuBar();
-
private JMenu menuTool = new JMenu();
-
private JMenuItem menuToolSquare = new JMenuItem();
-
private JMenuItem menuToolCircle = new JMenuItem();
-
private BorderLayout borderLayout1 = new BorderLayout();
-
private CanvasPanel canvasPanel = new CanvasPanel();
-
-
public X2Frame() {
-
try {
-
jbInit();
-
} catch (Exception e) {
-
e.printStackTrace();
-
}
-
}
-
-
private void jbInit() throws Exception {
-
this.setJMenuBar( menuBar );
-
this.getContentPane().setLayout(borderLayout1);
-
this.setSize( new Dimension(400, 300) );
-
this.setTitle( "Kevin Cameron" );
-
menuTool.setText("Tool");
-
menuTool.setMnemonic('T');
-
menuToolSquare.setText("Square");
-
menuToolSquare.setMnemonic('S');
-
menuToolSquare.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) {
-
menuToolSquare_ActionPerformed(e);
-
} } );
-
menuToolCircle.setText("Circle");
-
menuToolCircle.setMnemonic('C');
-
menuToolCircle.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e) {
-
menuToolCircle_actionPerformed(e);
-
}
-
});
-
menuTool.add( menuToolSquare );
-
menuTool.add(menuToolCircle);
-
menuBar.add(menuTool);
-
this.getContentPane().add(canvasPanel, BorderLayout.CENTER);
-
}
-
-
private void menuToolSquare_ActionPerformed(ActionEvent e) {
-
canvasPanel.setCircle(false);
-
}
-
-
private void menuToolCircle_actionPerformed(ActionEvent e) {
-
canvasPanel.setCircle(true);
-
}
-
}
-
-
-
import java.awt.Graphics2D;
-
-
public class Square extends Shape {
-
-
public Square(int x, int y) {
-
super.setX(x);
-
super.setY(y);
-
}
-
-
public void draw( Graphics2D g2 )
-
{
-
g2.drawRect(super.getX(), super.getY(), super.SHAPE_WIDTH, super.SHAPE_WIDTH);
-
}
-
}
-
-
store the shape in an arraylist and repaint the frame. When the frame repaints the menuBar gets painted again under the orignal.
Where is it? sorry if i can't find it....
Is this your complete code? only to choose shape then click to show those shapes? what about the quotes above?
I've test your code, no problem.... but i have doubt the quotes above.....
can you please add more details?
You didn't even set the close operation of your frame.... if you are using Windows, have a look at your task manager... many java process might still running.... they consumes your temp memory..... maybe anytime your system will crash....
sukatoa
Nope nothing is running, yes that is all my code.
It is suspost to be 6 classes. All the code does is allow you to chose a tool (Square, Circle) then paint that shape on the frame. It is all working fine except the menubar, and the shapes are being doubled under the orignal. If i re-size the window the doubles disapear, untill i draw another shap, then everything on the frame is being doubled.
i have set the exit
frame.setDefaul tCloseOperation ( JFrame.EXIT_ON_ CLOSE );
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Matt Stanley |
last post by:
I am trying to build a page that scales to fit the browser window regardless
of size or resolution. The navigation on the top of the page is framed in
dark red/brown using CSS with a background color specified in a custom class
tag.
I only want those cells that are using this custom class to be 1 pixel wide.
In the code I did not specify the <td> width but instead inserted a
single-pixel, transparent GIF and specified the dimensions of...
|
by: borges2003xx |
last post by:
hi everyone
can someone suggest me where find a lot programming tricks for
achieving the top speed in python?
thanks everyone for patience
|
by: mark |
last post by:
Hello-
i am trying to make the function addbitwise more efficient. the code
below takes an array of binary numbers (of size 5) and performs
bitwise addition. it looks ugly and it is not elegant but it appears
to work. using time, i measured it takes .041s to execute, which i
admit isnt much. but, the problem is that this procedure will be
called many, many times in my project (probably at least a few
thousand times, if not more) so...
|
by: batista |
last post by:
Hello all,
I have a third praty grid control...named C1grid. Im using it in one of
my apps..
Now, I have bind this grid to a custom dataset class named
"DataViewEx".
The code of the class is below...
Now what happens is that im updating this dataviewex class from a
separate thread.....
|
by: javuchi |
last post by:
I just want to share some code with you, and have some comments and
improvements if you want.
This header file allocates and add and delete items of any kind of data
from a very fast array:
#include <stdlib.h>
#ifndef __LIST_H__
#define __LIST_H__
| |
by: U S Contractors Offering Service A Non-profit |
last post by:
Brilliant technology helping those most in need Inbox
Reply
U S Contractors Offering Service A Non-profit
show details
10:37 pm (1 hour ago)
Brilliant technology helping those most in need Inbox
Reply
from Craig Somerford <uscos@2barter.net>
hide details 10:25 pm
(3 minutes ago)
|
by: Andy011 |
last post by:
Hi, I wanna know how to avoid the program to scan only the first letter of a string... I know it sounds real n00bish, but if you could post a simple example (SIMPLE, not like the help menu from c++) through C++ it'd be awesome :D.
Also, I would like to know how to color a text (What library should be used, how do you use a variable to color the text, and so on...).
P.S: The reason I need it fast is because I need to deliver a work...
|
by: Boris Ozegovic |
last post by:
Hi,
I am working on some system, and the communication will take place through
the chatterbot which will be written in AIML (interpreter is written in
Python). English is not my mother tongue, so I need huge favor: if all of
you can write two sentences, so that I could have greater pattern base.
The first sentence is finding someone's heart rate, example: "Please, can
you tell me John's heart rate", and the other one is setting the...
|
by: Vinod Sadanandan |
last post by:
Fast-Start Failover An Overview In Dataguard Environment
=============================================================================
This article describes the automatic fast start failover configuration and the conditions for trigerring a fast start failover in dataguard environment .
In Faststart failover dataguard configuration if the primary database becomes unavailable, the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |