Hello can any body help me to add color to my shape using jcombobox
please how can i fill color to my shape and change the line color of my shape using jcombobox here is my code
//package paint;
* PaintShapesDemo.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PaintShapesDemo extends JFrame implements ActionListener
final private int RECT =1 ;
final private int CIRCLE = 2;
final private int POLY = 3 ;
final private int ELLI = 4 ;
final private int TRAN = 5 ;
private int shape;
JLabel Lcolor;
JLabel Fcolor;
JLabel headlebel,linecolorlabel,fillcolorlabel,labeldisplay;
JButton recbutton,cirbutton,polygonbutton,ellipsebutton;
JComboBox linecolor,fillcolor;
private ButtonGroup grShapes = new ButtonGroup();
private JPanel shapeSelectionPanel = new JPanel(new FlowLayout());
public PaintShapesDemo()
super("HAKIMADE");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.white);
setSize(800,600);
setLocationRelativeTo(null);
recbutton = new JButton("CIRCLE");
cirbutton = new JButton("ROUNDRECT");
polygonbutton = new JButton("ELLIPSE");
ellipsebutton = new JButton("RECTANGLE");
JPanel TP=new JPanel();
TP.setLayout(new FlowLayout(FlowLayout.CENTER));
TP.add(new JLabel("MY PAINT APPLICATION."));
JPanel panel1=new JPanel();
panel1.setLayout(new FlowLayout(FlowLayout.CENTER,10,40));
panel1.add(recbutton);
panel1.add(cirbutton);
panel1.add(polygonbutton);
panel1.add(ellipsebutton);
JPanel TP1=new JPanel();
TP1.setLayout(new BorderLayout());
TP1.add(TP,BorderLayout.NORTH);
TP1.add(panel1,BorderLayout.CENTER);
JPanel panel2=new JPanel();
panel2.setLayout(new FlowLayout(FlowLayout.CENTER,30,2));
Lcolor = new JLabel("SELECT LINE COLOR");
Fcolor = new JLabel("SELECT FILL COLOR");
panel2.add(Lcolor);
panel2.add(Fcolor);
JPanel panel3=new JPanel();
panel3.setLayout(new FlowLayout(FlowLayout.CENTER,30,2));
linecolor = new JComboBox();
linecolor.addItem("Choose the color");
linecolor.addItem("Gray");
linecolor.addItem("Orange");
linecolor.addItem("Magenta");
linecolor.addItem("Dark Gray");
fillcolor = new JComboBox();
fillcolor.addItem("Choose the color");
fillcolor.addItem("RED");
fillcolor.addItem("BLUE");
fillcolor.addItem("BLACK");
fillcolor.addItem("YELLOW");
panel3.add(linecolor);
panel3.add(fillcolor);
JPanel panel4=new JPanel();
panel4.setLayout(new BorderLayout());
panel4.add(panel2,BorderLayout.NORTH);
panel4.add(panel3,BorderLayout.CENTER);
shapeSelectionPanel.add(TP1);
shapeSelectionPanel.add(panel4);
shapeSelectionPanel.setBackground(Color.green);
shapeSelectionPanel.setBorder(BorderFactory.createLineBorder(Color.black));
shapeSelectionPanel.setPreferredSize(new Dimension(110, 100));
add(shapeSelectionPanel, BorderLayout.NORTH);
add(new DrawingPanel());
recbutton.addActionListener(this);
cirbutton.addActionListener(this);
polygonbutton.addActionListener(this);
ellipsebutton.addActionListener(this);
public static void main(final String args[])
new PaintShapesDemo().setVisible(true);
public void actionPerformed(final ActionEvent e)
shape = CIRCLE;
if(e.getSource() == cirbutton)
shape = RECT;
if(e.getSource() == recbutton)
shape = POLY;
if(e.getSource() == polygonbutton)
shape = ELLI;
if(e.getSource() == ellipsebutton)
shape = TRAN;
class DrawingPanel extends JPanel
private Image img;
private Graphics2D g2;
public DrawingPanel()
addMouseListener(new MouseAdapter(){public void mousePressed(MouseEvent e){drawShape(e.getX(), e.getY());}});
public void paintComponent(final Graphics g)
if(img == null)
img = createImage(getWidth(), getHeight());
g2 = (Graphics2D)img.getGraphics();
g.drawImage(img,0,0,null);
private void drawShape(final int x, final int y)
switch (shape)
case POLY: g2.drawOval(x,y,100,100);break;
case ELLI: g2.drawOval(x,y,100,50);break;
case RECT: g2.drawRoundRect(x,y,100, 70, 20, 20);break;
case CIRCLE: g2.drawRect(x,y,100,80);break;
case TRAN: g2.drawRect(x,y,100,80);
repaint();
}
use CODE tags to post source code
read selected color from combobox and set colors Or declare two Strings lineColor and fillColor and set these variables on change of combo by adding ItemListener to the combo. and use that varables to set colors ..
Refer:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/Arcdemonstrationscalemoverotatesheer.htm
Similar Messages
-
My Imac is ejecting every disk inserted in it, I cannot access the disks, can any body help me troubleshoot the problem. I am using snow leopard.
Try resetting the SMC Intel-based Macs: Resetting the System Management Controller (SMC) - Apple Support
and PRAM How to Reset NVRAM on your Mac - Apple Support
If those don't help you can try a cleaning disc or a quick shot of compressed air. Chances are that your drive has failed, join the club it's not all that uncommon. You can either have it replaced or purchase an inexpensive external drive. Don't buy the cute little Apple USB Superdrive, it won't work on macs with internal drives working or not. -
on my macbook pro when opening a page on safaryi can not save it as a pdf only give me the option of saving it as a web page can any body help me on this I have tryed so many times without success?
Just select Print in Safari and then, in the bottom left-hand corner, select PDF and you can save it to whichever flavor pdf file you like.
Clinton -
My Imac is ejecting every disk inserted in it, I cannot access the disks, can any body help me troubleshoot the problem
The frist thing to try is a drive-n disk. They are cheap (US$5-15) and easy to use. Many unresponsive drives, even ones declared "dead" by an Apple tech, have returned to service after a cleaning.
Check with home entertainment specialty shops, electronic superstores and office supply outlets that sell computer accessories. -
Please can any body help me out where can I find link to download ALDSP2.5
Hi All,
Please can any body help me out where can I find link to download ALDSP2.5.
I am trying since last couple of days as I am not able to find it. please some body help me out in this regard. I appriciate even if I get a link to download ALDSP3.0.
thanks in advance.
Please mail me the links at [email protected]
rajen.
Edited by: user13358281 on Jul 2, 2010 2:57 PMHello Werner,
Thanks for response, but I couldn't find the same.
Still my search is going on. I dont know why oracle people made this that dificult, If I am not wrong I think earlier i could easily locate the previous version artifacts(softwares) easily. but now why they made that complicated.. no clues.
any ways thanks once again. -
i forgot the password of my iphone 3g and when i try to restore it it shows the message"my iphone 3g could not be restored an unknown error occurred(1015)" can any body help please..
This error normally appears if you attempted to downgrade or modify your iOS. See here http://support.apple.com/kb/TS3694#error1015
-
hi i updated my iphone 4 with itunes and now i cannot use my phone as i keep getting error 16 after trying to restore my phone....i cannot afford to replace ..can any body help me...the phone is out of warrenty so apple do not want to know....please any help
https://discussions.apple.com/message/23100453#23100453
more hits from the search
https://www.google.dk/search?q=restore+itphone+error+16&oq=restore+itphone+error +16&aqs=chrome..69i57j0l5.11485j0j7&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8 -
I can not connect to ITunes Store to download updates. I have no trouble connecting to the internet. It worked OK up to about a last month. can any body help.
Hi there bigyellowdigger!
I have an article here that can help you troubleshoot this issue with your connection to the iTunes Store. That article can be found right here:
Can't connect to the iTunes Store
http://support.apple.com/kb/ts1368
Take care, and thanks for visiting the Apple Support Communities.
-Braden -
I have a brand new i phone 4s and i have updated the soft ware to the 5.1 and tried to restore it to download my old contacts and apps etc. and my computer now wont recognise my phone and itunes will not do anything can any body help please???? i need this sorting asap xxxxxxx
see if this link helps http://support.apple.com/kb/TS1538
-
I am trying to find a driver to syn mini mac to Lexmark x9350. Can any body help please?
Humm... the only Lexmark X9300 download that I see is for SL 10.6...?
Lexmark United States Support & Downloads for Lexmark X9350
I'm not sure exactly what "component missing" means, but it sounds more like a missing driver than a missing printer part?
To be honest, I think your going to have to remove all previous Lexmark drivers and software from your system, temporarily connect the printer up USB and use the system updater as per the link that I posted in my first reply.
Lexmark United States
You might also check to see if you have a failed print job..?
Open the Print & Fax Preferences and select Open Print Queue...
Pause the Printer using the green button.
Select (highlight) each of the jobs in Status and Delete them all.
Resume Printer using the green button and send it a new job. -
Can any body help me to prepare f.s for!
can any body help me to prepare f.s for!
all material movements and asociated accoutning document?
all open purchase orders for a given plant and delivery period?Hi
what do you mean by f.s, is it functional specification?
Material document associated accounting document you can find MSEG and BSEG tables
Open Purchase Orders for a given plant and delivery period
Purchase orders infirmation is available in EKKO (Header) and EKPO (Item)
Take the information from EKKO by company code, pass it on to EKPO by plant (WERKS)which is not equal to (EKPO -ELIKZ) for open PO and for delivery date (EKET-EINDT).
please check and let me know if you need anything.
regards
Srinivas -
Hello can some body help me on my icloud app.i cannot send an email with iCloud
Hello
can some body help me on my icloud app.i cannot send an email with iCloud
excuse me my englishHello
thanks for your prompt response
yes i defined an account for icloud
Regards
Faisal Djama -
I have to install Oracle 9.2 on Solaris 9 I have no clue can any body help
I have to install Oracle 9.2 on Solaris 9 I have no clue can any body help me I havent installed oracle on any Unix based system only done on Windows based by running the oracle installer can any one guide me how to accomplish this Task. any detailed step by step how to install from CD drive how to mount it. Please reply
ThanksHi,
<br></br>
<br>You can help with this doc Oracle9i Installation Guide Release 2 (9.2.0.1.0) for UNIX Systems: AIX-Based Systems, Compaq Tru64 UNIX, HP 9000 Series HP-UX, Linux Intel, and Sun Solaris</br>
<br>Bests reagards,</br>
<br>Nicolas</br> -
I am trying to capture using firewire 800 to 400 adaptor through a Sony HDV VTR. The VTR is not recognizing can some body help me solve this problem.
I am using FCP7 and IMAC with 10.6.8 version os
I dont have a 6 pin or 400 firewire port in the systemLet's start with basics.
Does your computer recognize that there is a VTR attached?
• Open up system profiler>Hardware>FireWire. Does your machine show up?
If no, you need to figure out if the problem lies with the VTR, the cable, the adapter or your computer.
My guess is with the adapter. A number of people have expressed frustration getting fw400 device to work through fw800 ports.
If that's your problem, see if you can find an older Mac w/ fw400 ports or a dedicated fw800 to 400 cable.
good luck,
x
ps - In "locking the barn after the paddle has been lost upstream" mode, this is why non-expandable computers like the iMac are so problematic. A MacBookPro with the expresscard 34 slot or a MacPro with 3 slots can work around these kind of issues. A closed box like the iMac is a dead end. Sorry. -
Can any body help me in creating a jar using Weblogic server tool
I have created the class files of the container manged bean successfully.I want to create the jar file using the weblogic tool.
I have created a new jar file and now I have to add a bean class file and a home class file to it.In the tool I choose a the path using the choose button.When I say next it complaints that it cannot locate the bean files.
Can any body please help me soon..
waiting for your reply.I had similar problems with the WLS deploy tool. I think they were solved by making sure that I started the tool from the directory that contained the root package of my EJBs.
It might work...
Maybe you are looking for
-
Open request not showing in the report
Hi, We have built a query for planning to show open request. After 50,000 records, the request would be closed in the infoprovider. In the query, Request id is restricted with the most current data variable. In Dev, the report shows the open request.
-
Macbook Pro keeps going to sleep / not waking up
Hello all, I'm having trouble with my MacBook Pro going to sleep randomly. I will be working on the computer, and everything will go black. I can still here the computer running. When trying to wake it up from what seems like sleep, no buttons will w
-
Hi All Had a quick question about a SQL Query in a JSP - Can I duplicated an exact same record in a table with a new primary key without using the insert statement?? Say for example I have the following table: OrderNo OrderName OrderType ======= ====
-
I have a ipad and ipod. I can not download any music with itunes. Please help me find itunes that works with windows 8. Thank You, Patricia Graham
-
Dropped data in SAXParser client xml over http
Hi all, I need some expert help. I have succeeded in getting our server to encode small gif image files using base64, and transmitting the resulting text in XML back to a client using SAXParser via http. The client overrides characters(char[] ch, int