Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

GUI Components Part 1 is the only part to this lab. Create a folder named Unit08 and place all your files for this assignment in

GUI Components Part 1 is the only part to this lab. Create a folder named Unit08 and place all your files for this assignment in that folder. You will create a program called Unit08_Prog01.java. This program will display a graphical user interface (GUI) . The window has a title of "Unit08_Prog01" and three panes stacked one on top of the other. The top most pane holds five radio buttons, one for each color of: Red, Yellow, White, Orange and Green. The White radio button is set by default. Clicking on a radio button will change the background color of the text area in the second panel to the color indicated by the radio button label. The second pane contains the text "Programming is fun". Version 3.0 Page: The third pane contains two buttons. Clicking the button marked "<=" will cause the text to move to the left, clicking on the button marked "=>" will move the text to the right. I have everything done besides the arrows that move the text left and right. Here is my code so far. public class unit08_prog01 extends JFrame { JRadioButton red = new JRadioButton("red"); JRadioButton yellow = new JRadioButton("yellow"); JRadioButton white = new JRadioButton("white"); JRadioButton gray = new JRadioButton("gray"); JRadioButton green = new JRadioButton("green"); JButton left = new JButton("<="); JButton right = new JButton("=>"); Font font = new Font("Verdana", Font.BOLD, 20); public static void main(String[] args) { JFrame frame = new unit08_prog01(); frame.setTitle("unit08_prog01"); frame.setSize(500,200); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public unit08_prog01() { JPanel RadioButtons = new JPanel(); RadioButtons.setLayout(new GridLayout(1, 5)); RadioButtons.add(red); RadioButtons.add(yellow); RadioButtons.add(white); RadioButtons.add(gray); RadioButtons.add(green); RadioButtons.setBorder(new TitledBorder("Set Background Color")); add(RadioButtons, BorderLayout.NORTH); ButtonGroup group = new ButtonGroup(); group.add(red); group.add(yellow); group.add(white); group.add(gray); group.add(green); white.setSelected(true); JTextArea content = new JTextArea("Programming is fun", 5, 5); content.setLineWrap(true); content.setWrapStyleWord(true); content.setEditable(true); content.setFont(font); JScrollPane scrollPane = new JScrollPane(content); add(scrollPane, BorderLayout.CENTER); JPanel Buttons = new JPanel(); Buttons.setLayout(new GridLayout(1, 2)); Buttons.add(left); Buttons.add(right); add(Buttons, BorderLayout.SOUTH); left.setMnemonic('L'); right.setMnemonic('R'); red.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ content.setBackground(Color.red); } }); yellow.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ content.setBackground(Color.yellow); } }); white.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ content.setBackground(Color.white); } }); gray.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ content.setBackground(Color.gray); } }); green.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ content.setBackground(Color.green); } }); left.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ content.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); } }); right.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ content.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); } }); } } Any help would be appreciated!!

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

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago