Question
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.
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started