Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Swing problem I have this code that work perfectly it created the Jmenu bar with radio button on it how do i create a

java Swing problem

I have this code that work perfectly it created the Jmenu bar with radio button on it

how do i create a toolBar out of this and connect it together so when i choose rectangle on tool bar in jmenu tools radio button rectangle also been choosen.

image text in transcribed

import javax.swing.ButtonGroup; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem;

public class PaintProgram extends JFrame { public PaintProgram() { JMenuBar menuBar = new JMenuBar(); JMenu optionsMenu, toolsMenu, helpMenu; optionsMenu = new JMenu("Options"); toolsMenu = new JMenu("Tools"); helpMenu = new JMenu("Help"); JRadioButtonMenuItem lineMenuItem, pencilMenuItem, rectangleMenuItem, elipseMenuItem; ImageIcon lineIcon, pencilIcon, rectangleIcon, elipseIcon; lineIcon = new ImageIcon("line.png"); lineMenuItem = new JRadioButtonMenuItem("Line", lineIcon); pencilIcon = new ImageIcon("pencil.png"); pencilMenuItem = new JRadioButtonMenuItem("Pencil", pencilIcon); rectangleIcon = new ImageIcon("rectangle.png"); rectangleMenuItem = new JRadioButtonMenuItem("Rectangle", rectangleIcon); elipseIcon = new ImageIcon("elipse.png"); elipseMenuItem = new JRadioButtonMenuItem("Elipse", elipseIcon); ButtonGroup menuItemsButtonGroup = new ButtonGroup(); menuItemsButtonGroup.add(lineMenuItem); menuItemsButtonGroup.add(pencilMenuItem); menuItemsButtonGroup.add(rectangleMenuItem); menuItemsButtonGroup.add(elipseMenuItem); toolsMenu.add(lineMenuItem); toolsMenu.add(pencilMenuItem); toolsMenu.add(rectangleMenuItem); toolsMenu.add(elipseMenuItem); menuBar.add(optionsMenu); menuBar.add(toolsMenu); menuBar.add(helpMenu); this.setJMenuBar(menuBar); } public static void main(String[] args) { PaintProgram paintProgram = new PaintProgram(); paintProgram.setSize(500, 400); paintProgram.setTitle("Paint Program"); paintProgram.setVisible(true); } }

Options Tools Help Line O Pencil Rectangle OO Ellipse color." |\ Line l p Pencil Rectangle l Ellipse

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

What is focal length? Explain with a diagram and give an example.

Answered: 1 week ago

Question

What is physics and how does it apply in daily life?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago