SlideShare a Scribd company logo
1 of 7
Download to read offline
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
public class DrawApp extends JFrame {
//declaring data fields
private Drawable selectedFig = null;
//default border color
private Color presentBorderColor = Color.BLACK;
private Color presentInteriorrColor = Color.WHITE;
private Drawable[] theFigKinds;
// Constructor
private DrawApp(String args[]) {
//title
super("Draw App");
//frame size
setSize(650, 650);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loadFigKinds(args);
JMenu drawingToolMenu = createDrawingToolMenu();
JToolBar drawingToolToolBar = createDrawingToolToolBar();
selectedFig = theFigKinds[0];
JMenu colorMenu = createColorMenu();
JMenuBar menuBar = new JMenuBar();
menuBar.add(colorMenu);
menuBar.add(drawingToolMenu);
setJMenuBar(menuBar);
getContentPane().add(drawingToolToolBar, BorderLayout.EAST);
getContentPane().add(new DrawPanel(this),
BorderLayout.CENTER);
}
// creating drawing tool menu
private JMenu createDrawingToolMenu() {
JMenu drawingToolMenu = new JMenu("Drawing Tool");
for (int i = 0; i < theFigKinds.length; i++) {
// create a menu item for this figure kind
JMenuItem item = new JMenuItem(theFigKinds[i].getName());
// set the action listener
item.addActionListener(new ToolSelector(theFigKinds[i]));
// add the item to the menu
drawingToolMenu.add(item);
}
return drawingToolMenu;
}
// creating menu tool bar
JToolBar createDrawingToolToolBar() {
JToolBar drawingToolToolBar = new JToolBar(JToolBar.VERTICAL);
for (int i = 0; i < theFigKinds.length; i++) {
JButton aButton = new JButton(theFigKinds[i].getIcon(16));
aButton.addActionListener(new ToolSelector(theFigKinds[i]));
drawingToolToolBar.add(aButton);
}
return drawingToolToolBar;
}
//creating color menu
private JMenu createColorMenu() {
JMenu colorMenu = new JMenu("Colors");
JMenuItem setInteriorColor
= new JMenuItem("Set Interior Color");
setInteriorColor.addActionListener(new SetInteriorColor());
colorMenu.add(setInteriorColor);
JMenuItem setBorderColor = new JMenuItem("Set Border Color");
setBorderColor.addActionListener(new SetBorderColor());
colorMenu.add(setBorderColor);
return colorMenu;
}
public Drawable getSelectedFig() {
return selectedFig;
}
public static void main(String args[]) {
DrawApp drawApp = new DrawApp(args);
drawApp.setVisible(true);
}
// Inner Classes
private class ToolSelector implements ActionListener {
// Data Fields
private Drawable desiredFig;
// Constructor
public ToolSelector(Drawable desiredFig) {
this.desiredFig = desiredFig;
}
// Methods
@Override
public void actionPerformed(ActionEvent e) {
selectedFig = desiredFig;
}
}
private class SetInteriorColor implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
presentInteriorrColor
= JColorChooser.showDialog(
DrawApp.this,
"Select Interior Color",
presentInteriorrColor);
for (int i = 0; i < theFigKinds.length; i++) {
theFigKinds[i].setInteriorColor(presentInteriorrColor);
}
repaint();
}
}
}
Solution
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
public class DrawApp extends JFrame {
//declaring data fields
private Drawable selectedFig = null;
//default border color
private Color presentBorderColor = Color.BLACK;
private Color presentInteriorrColor = Color.WHITE;
private Drawable[] theFigKinds;
// Constructor
private DrawApp(String args[]) {
//title
super("Draw App");
//frame size
setSize(650, 650);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loadFigKinds(args);
JMenu drawingToolMenu = createDrawingToolMenu();
JToolBar drawingToolToolBar = createDrawingToolToolBar();
selectedFig = theFigKinds[0];
JMenu colorMenu = createColorMenu();
JMenuBar menuBar = new JMenuBar();
menuBar.add(colorMenu);
menuBar.add(drawingToolMenu);
setJMenuBar(menuBar);
getContentPane().add(drawingToolToolBar, BorderLayout.EAST);
getContentPane().add(new DrawPanel(this),
BorderLayout.CENTER);
}
// creating drawing tool menu
private JMenu createDrawingToolMenu() {
JMenu drawingToolMenu = new JMenu("Drawing Tool");
for (int i = 0; i < theFigKinds.length; i++) {
// create a menu item for this figure kind
JMenuItem item = new JMenuItem(theFigKinds[i].getName());
// set the action listener
item.addActionListener(new ToolSelector(theFigKinds[i]));
// add the item to the menu
drawingToolMenu.add(item);
}
return drawingToolMenu;
}
// creating menu tool bar
JToolBar createDrawingToolToolBar() {
JToolBar drawingToolToolBar = new JToolBar(JToolBar.VERTICAL);
for (int i = 0; i < theFigKinds.length; i++) {
JButton aButton = new JButton(theFigKinds[i].getIcon(16));
aButton.addActionListener(new ToolSelector(theFigKinds[i]));
drawingToolToolBar.add(aButton);
}
return drawingToolToolBar;
}
//creating color menu
private JMenu createColorMenu() {
JMenu colorMenu = new JMenu("Colors");
JMenuItem setInteriorColor
= new JMenuItem("Set Interior Color");
setInteriorColor.addActionListener(new SetInteriorColor());
colorMenu.add(setInteriorColor);
JMenuItem setBorderColor = new JMenuItem("Set Border Color");
setBorderColor.addActionListener(new SetBorderColor());
colorMenu.add(setBorderColor);
return colorMenu;
}
public Drawable getSelectedFig() {
return selectedFig;
}
public static void main(String args[]) {
DrawApp drawApp = new DrawApp(args);
drawApp.setVisible(true);
}
// Inner Classes
private class ToolSelector implements ActionListener {
// Data Fields
private Drawable desiredFig;
// Constructor
public ToolSelector(Drawable desiredFig) {
this.desiredFig = desiredFig;
}
// Methods
@Override
public void actionPerformed(ActionEvent e) {
selectedFig = desiredFig;
}
}
private class SetInteriorColor implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
presentInteriorrColor
= JColorChooser.showDialog(
DrawApp.this,
"Select Interior Color",
presentInteriorrColor);
for (int i = 0; i < theFigKinds.length; i++) {
theFigKinds[i].setInteriorColor(presentInteriorrColor);
}
repaint();
}
}
}

More Related Content

Similar to import java.awt.BorderLayout; import java.awt.Color; import java.pdf

correct the error and add code same in the pic import jav.pdf
correct the error and add code same in the pic   import jav.pdfcorrect the error and add code same in the pic   import jav.pdf
correct the error and add code same in the pic import jav.pdf
devangmittal4
 
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdfJAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
arihantmobileselepun
 
Task Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdfTask Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdf
cronkwurphyb44502
 
i need a output screen shot for this code import java-awt-BorderLayou.docx
i need a output  screen shot for this code import java-awt-BorderLayou.docxi need a output  screen shot for this code import java-awt-BorderLayou.docx
i need a output screen shot for this code import java-awt-BorderLayou.docx
PaulntmMilleri
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
arccreation001
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdf
arvindarora20042013
 
This is Java, What I am creating is a multi lab pacman type game.T.pdf
This is Java, What I am creating is a multi lab pacman type game.T.pdfThis is Java, What I am creating is a multi lab pacman type game.T.pdf
This is Java, What I am creating is a multi lab pacman type game.T.pdf
fashionscollect
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
cymbron
 

Similar to import java.awt.BorderLayout; import java.awt.Color; import java.pdf (20)

correct the error and add code same in the pic import jav.pdf
correct the error and add code same in the pic   import jav.pdfcorrect the error and add code same in the pic   import jav.pdf
correct the error and add code same in the pic import jav.pdf
 
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdfJAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
 
Task Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdfTask Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdf
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
i need a output screen shot for this code import java-awt-BorderLayou.docx
i need a output  screen shot for this code import java-awt-BorderLayou.docxi need a output  screen shot for this code import java-awt-BorderLayou.docx
i need a output screen shot for this code import java-awt-BorderLayou.docx
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
 
Grain final border one
Grain final border oneGrain final border one
Grain final border one
 
(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx
(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx
(ArrayIndexOutOfBoundsException) Modifythe program from the code bel.docx
 
Java!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdfJava!!!!!Create a program that authenticates username and password.pdf
Java!!!!!Create a program that authenticates username and password.pdf
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with Griffon
 
Groovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonGroovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With Griffon
 
jframe, jtextarea and jscrollpane
  jframe, jtextarea and jscrollpane  jframe, jtextarea and jscrollpane
jframe, jtextarea and jscrollpane
 
Help with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docxHelp with Java! Can someone check my code What I am trying to accompli.docx
Help with Java! Can someone check my code What I am trying to accompli.docx
 
Program imageviewer
Program imageviewerProgram imageviewer
Program imageviewer
 
This is Java, What I am creating is a multi lab pacman type game.T.pdf
This is Java, What I am creating is a multi lab pacman type game.T.pdfThis is Java, What I am creating is a multi lab pacman type game.T.pdf
This is Java, What I am creating is a multi lab pacman type game.T.pdf
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
Settings
SettingsSettings
Settings
 

More from anwarfoot

First, lets analyze what each component of the .pdf
                     First, lets analyze what each component of the .pdf                     First, lets analyze what each component of the .pdf
First, lets analyze what each component of the .pdf
anwarfoot
 
One of the four prominent symptoms of typhoid is coated tongue. Even.pdf
One of the four prominent symptoms of typhoid is coated tongue. Even.pdfOne of the four prominent symptoms of typhoid is coated tongue. Even.pdf
One of the four prominent symptoms of typhoid is coated tongue. Even.pdf
anwarfoot
 
Meselson and Stahl in 1957 gave experimental evidence that each DNA .pdf
Meselson and Stahl in 1957 gave experimental evidence that each DNA .pdfMeselson and Stahl in 1957 gave experimental evidence that each DNA .pdf
Meselson and Stahl in 1957 gave experimental evidence that each DNA .pdf
anwarfoot
 
Introduction One of the key goals for the Windows Subsystem for Li.pdf
Introduction One of the key goals for the Windows Subsystem for Li.pdfIntroduction One of the key goals for the Windows Subsystem for Li.pdf
Introduction One of the key goals for the Windows Subsystem for Li.pdf
anwarfoot
 

More from anwarfoot (20)

0 to -1 Solution 0 to -1 .pdf
  0 to -1  Solution  0 to -1  .pdf  0 to -1  Solution  0 to -1  .pdf
0 to -1 Solution 0 to -1 .pdf
 
phosphate group and deoxyribose The groups are .pdf
                     phosphate group and deoxyribose  The groups are  .pdf                     phosphate group and deoxyribose  The groups are  .pdf
phosphate group and deoxyribose The groups are .pdf
 
Osmosis .pdf
                     Osmosis                                      .pdf                     Osmosis                                      .pdf
Osmosis .pdf
 
in case of solid oxygen the atoms of oxygen are s.pdf
                     in case of solid oxygen the atoms of oxygen are s.pdf                     in case of solid oxygen the atoms of oxygen are s.pdf
in case of solid oxygen the atoms of oxygen are s.pdf
 
Yeast is a microorganism and doesnt itself rise.pdf
                     Yeast is a microorganism and doesnt itself rise.pdf                     Yeast is a microorganism and doesnt itself rise.pdf
Yeast is a microorganism and doesnt itself rise.pdf
 
First, lets analyze what each component of the .pdf
                     First, lets analyze what each component of the .pdf                     First, lets analyze what each component of the .pdf
First, lets analyze what each component of the .pdf
 
when they reach equilibrium te cell potential is .pdf
                     when they reach equilibrium te cell potential is .pdf                     when they reach equilibrium te cell potential is .pdf
when they reach equilibrium te cell potential is .pdf
 
E° = 0.07 - (0.14)     = 0.21 V 2UO22+(aq) + Sn(s.pdf
                     E° = 0.07 - (0.14)     = 0.21 V 2UO22+(aq) + Sn(s.pdf                     E° = 0.07 - (0.14)     = 0.21 V 2UO22+(aq) + Sn(s.pdf
E° = 0.07 - (0.14)     = 0.21 V 2UO22+(aq) + Sn(s.pdf
 
D) Not B) because Cl-Benzene bond develops a doub.pdf
                     D) Not B) because Cl-Benzene bond develops a doub.pdf                     D) Not B) because Cl-Benzene bond develops a doub.pdf
D) Not B) because Cl-Benzene bond develops a doub.pdf
 
YesBecause (1,1) is missing, it is not reflexive though (3,3) (2,2.pdf
YesBecause (1,1) is missing, it is not reflexive though (3,3) (2,2.pdfYesBecause (1,1) is missing, it is not reflexive though (3,3) (2,2.pdf
YesBecause (1,1) is missing, it is not reflexive though (3,3) (2,2.pdf
 
We know that from Nernst Equation ,E o cell = E o – ( 0.059 n ) .pdf
We know that from Nernst Equation ,E o cell = E o – ( 0.059  n ) .pdfWe know that from Nernst Equation ,E o cell = E o – ( 0.059  n ) .pdf
We know that from Nernst Equation ,E o cell = E o – ( 0.059 n ) .pdf
 
lower.. think about it.. take a straw draw a line.pdf
                     lower.. think about it.. take a straw draw a line.pdf                     lower.. think about it.. take a straw draw a line.pdf
lower.. think about it.. take a straw draw a line.pdf
 
r= 1+ sin theta drd = cos = 0Therefore = 2Solutionr=.pdf
r= 1+ sin theta drd = cos = 0Therefore = 2Solutionr=.pdfr= 1+ sin theta drd = cos = 0Therefore = 2Solutionr=.pdf
r= 1+ sin theta drd = cos = 0Therefore = 2Solutionr=.pdf
 
From left to right iodocyclopropane; 1-bromo-3-m.pdf
                     From left to right iodocyclopropane; 1-bromo-3-m.pdf                     From left to right iodocyclopropane; 1-bromo-3-m.pdf
From left to right iodocyclopropane; 1-bromo-3-m.pdf
 
For inorganic compounds Chemical properties remai.pdf
                     For inorganic compounds Chemical properties remai.pdf                     For inorganic compounds Chemical properties remai.pdf
For inorganic compounds Chemical properties remai.pdf
 
n=4 l=3 we know that L=h2(l(l+1))L=3.710-34Solutionn.pdf
n=4 l=3 we know that L=h2(l(l+1))L=3.710-34Solutionn.pdfn=4 l=3 we know that L=h2(l(l+1))L=3.710-34Solutionn.pdf
n=4 l=3 we know that L=h2(l(l+1))L=3.710-34Solutionn.pdf
 
Over forty interstellar molecules have been found, ranging from simp.pdf
Over forty interstellar molecules have been found, ranging from simp.pdfOver forty interstellar molecules have been found, ranging from simp.pdf
Over forty interstellar molecules have been found, ranging from simp.pdf
 
One of the four prominent symptoms of typhoid is coated tongue. Even.pdf
One of the four prominent symptoms of typhoid is coated tongue. Even.pdfOne of the four prominent symptoms of typhoid is coated tongue. Even.pdf
One of the four prominent symptoms of typhoid is coated tongue. Even.pdf
 
Meselson and Stahl in 1957 gave experimental evidence that each DNA .pdf
Meselson and Stahl in 1957 gave experimental evidence that each DNA .pdfMeselson and Stahl in 1957 gave experimental evidence that each DNA .pdf
Meselson and Stahl in 1957 gave experimental evidence that each DNA .pdf
 
Introduction One of the key goals for the Windows Subsystem for Li.pdf
Introduction One of the key goals for the Windows Subsystem for Li.pdfIntroduction One of the key goals for the Windows Subsystem for Li.pdf
Introduction One of the key goals for the Windows Subsystem for Li.pdf
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

import java.awt.BorderLayout; import java.awt.Color; import java.pdf

  • 1. import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JColorChooser; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JToolBar; public class DrawApp extends JFrame { //declaring data fields private Drawable selectedFig = null; //default border color private Color presentBorderColor = Color.BLACK; private Color presentInteriorrColor = Color.WHITE; private Drawable[] theFigKinds; // Constructor private DrawApp(String args[]) { //title super("Draw App"); //frame size setSize(650, 650); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); loadFigKinds(args); JMenu drawingToolMenu = createDrawingToolMenu(); JToolBar drawingToolToolBar = createDrawingToolToolBar(); selectedFig = theFigKinds[0]; JMenu colorMenu = createColorMenu(); JMenuBar menuBar = new JMenuBar(); menuBar.add(colorMenu); menuBar.add(drawingToolMenu); setJMenuBar(menuBar);
  • 2. getContentPane().add(drawingToolToolBar, BorderLayout.EAST); getContentPane().add(new DrawPanel(this), BorderLayout.CENTER); } // creating drawing tool menu private JMenu createDrawingToolMenu() { JMenu drawingToolMenu = new JMenu("Drawing Tool"); for (int i = 0; i < theFigKinds.length; i++) { // create a menu item for this figure kind JMenuItem item = new JMenuItem(theFigKinds[i].getName()); // set the action listener item.addActionListener(new ToolSelector(theFigKinds[i])); // add the item to the menu drawingToolMenu.add(item); } return drawingToolMenu; } // creating menu tool bar JToolBar createDrawingToolToolBar() { JToolBar drawingToolToolBar = new JToolBar(JToolBar.VERTICAL); for (int i = 0; i < theFigKinds.length; i++) { JButton aButton = new JButton(theFigKinds[i].getIcon(16)); aButton.addActionListener(new ToolSelector(theFigKinds[i])); drawingToolToolBar.add(aButton); } return drawingToolToolBar; } //creating color menu private JMenu createColorMenu() { JMenu colorMenu = new JMenu("Colors"); JMenuItem setInteriorColor = new JMenuItem("Set Interior Color"); setInteriorColor.addActionListener(new SetInteriorColor()); colorMenu.add(setInteriorColor); JMenuItem setBorderColor = new JMenuItem("Set Border Color"); setBorderColor.addActionListener(new SetBorderColor());
  • 3. colorMenu.add(setBorderColor); return colorMenu; } public Drawable getSelectedFig() { return selectedFig; } public static void main(String args[]) { DrawApp drawApp = new DrawApp(args); drawApp.setVisible(true); } // Inner Classes private class ToolSelector implements ActionListener { // Data Fields private Drawable desiredFig; // Constructor public ToolSelector(Drawable desiredFig) { this.desiredFig = desiredFig; } // Methods @Override public void actionPerformed(ActionEvent e) { selectedFig = desiredFig; } } private class SetInteriorColor implements ActionListener { @Override public void actionPerformed(ActionEvent e) { presentInteriorrColor = JColorChooser.showDialog( DrawApp.this, "Select Interior Color", presentInteriorrColor); for (int i = 0; i < theFigKinds.length; i++) { theFigKinds[i].setInteriorColor(presentInteriorrColor); } repaint();
  • 4. } } } Solution import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JColorChooser; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JToolBar; public class DrawApp extends JFrame { //declaring data fields private Drawable selectedFig = null; //default border color private Color presentBorderColor = Color.BLACK; private Color presentInteriorrColor = Color.WHITE; private Drawable[] theFigKinds; // Constructor private DrawApp(String args[]) { //title super("Draw App"); //frame size setSize(650, 650); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); loadFigKinds(args); JMenu drawingToolMenu = createDrawingToolMenu(); JToolBar drawingToolToolBar = createDrawingToolToolBar(); selectedFig = theFigKinds[0];
  • 5. JMenu colorMenu = createColorMenu(); JMenuBar menuBar = new JMenuBar(); menuBar.add(colorMenu); menuBar.add(drawingToolMenu); setJMenuBar(menuBar); getContentPane().add(drawingToolToolBar, BorderLayout.EAST); getContentPane().add(new DrawPanel(this), BorderLayout.CENTER); } // creating drawing tool menu private JMenu createDrawingToolMenu() { JMenu drawingToolMenu = new JMenu("Drawing Tool"); for (int i = 0; i < theFigKinds.length; i++) { // create a menu item for this figure kind JMenuItem item = new JMenuItem(theFigKinds[i].getName()); // set the action listener item.addActionListener(new ToolSelector(theFigKinds[i])); // add the item to the menu drawingToolMenu.add(item); } return drawingToolMenu; } // creating menu tool bar JToolBar createDrawingToolToolBar() { JToolBar drawingToolToolBar = new JToolBar(JToolBar.VERTICAL); for (int i = 0; i < theFigKinds.length; i++) { JButton aButton = new JButton(theFigKinds[i].getIcon(16)); aButton.addActionListener(new ToolSelector(theFigKinds[i])); drawingToolToolBar.add(aButton); } return drawingToolToolBar; } //creating color menu private JMenu createColorMenu() { JMenu colorMenu = new JMenu("Colors"); JMenuItem setInteriorColor
  • 6. = new JMenuItem("Set Interior Color"); setInteriorColor.addActionListener(new SetInteriorColor()); colorMenu.add(setInteriorColor); JMenuItem setBorderColor = new JMenuItem("Set Border Color"); setBorderColor.addActionListener(new SetBorderColor()); colorMenu.add(setBorderColor); return colorMenu; } public Drawable getSelectedFig() { return selectedFig; } public static void main(String args[]) { DrawApp drawApp = new DrawApp(args); drawApp.setVisible(true); } // Inner Classes private class ToolSelector implements ActionListener { // Data Fields private Drawable desiredFig; // Constructor public ToolSelector(Drawable desiredFig) { this.desiredFig = desiredFig; } // Methods @Override public void actionPerformed(ActionEvent e) { selectedFig = desiredFig; } } private class SetInteriorColor implements ActionListener { @Override public void actionPerformed(ActionEvent e) { presentInteriorrColor = JColorChooser.showDialog( DrawApp.this, "Select Interior Color",
  • 7. presentInteriorrColor); for (int i = 0; i < theFigKinds.length; i++) { theFigKinds[i].setInteriorColor(presentInteriorrColor); } repaint(); } } }