I need to convert this application to a gui application using JFrame /* Rings.ja
ID: 3637044 • Letter: I
Question
I need to convert this application to a gui application using JFrame/* Rings.java
Programmer: Aaron Monhollen
Date: January 16, 2012
Purpose: To create an application and afterwards turn it into a gui application.
*/
// import necessary requirements
import javax.swing.*;
import java.awt.*;
// class header
public class Rings extends JApplet
{
// main method header
public static final int RING_DIAMETER = 80;
public static final int RING_X_OFFSET = 50;
public static final int RING_Y_OFFSET = 50;
public void paint(Graphics canvas)
{
canvas.setColor(Color.BLUE);
canvas.drawOval(0,0, RING_DIAMETER, RING_DIAMETER);
canvas.setColor(Color.BLACK);
canvas.drawOval(2*RING_X_OFFSET,0,RING_DIAMETER,RING_DIAMETER);
canvas.setColor(Color.RED);
canvas.drawOval(4*RING_X_OFFSET,0,RING_DIAMETER,RING_DIAMETER);
canvas.setColor(Color.YELLOW);
canvas.drawOval(RING_X_OFFSET,RING_Y_OFFSET,RING_DIAMETER,RING_DIAMETER);
canvas.setColor(Color.GREEN);
canvas.drawOval(3*RING_X_OFFSET,RING_Y_OFFSET,RING_DIAMETER,RING_DIAMETER);
}
}
This program runs fine! Now I need to convert it to a gui and fix the bugs given.
Change the application to a gui application using JFrame . You do not need to write a totally separate program, change the existing one.
Explanation / Answer
mport javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.ImageIcon; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JMenuBar; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class BodyMass extends JFrame implements ActionListener { JTextField T1,T2,T3,T4; public BodyMass() { JPanel P1=new JPanel(); JPanel P2=new JPanel(); JPanel P3=new JPanel(); FlowLayout W=new FlowLayout(); Font N=new Font("Tahoma",Font.BOLD,20); T1=new JTextField(5); T2=new JTextField(5); T3=new JTextField(15); T4=new JTextField(10); add(P1,BorderLayout.NORTH); add(P2,BorderLayout.CENTER); add(P3,BorderLayout.SOUTH); JLabel L1=new JLabel("Hight in cm"); JLabel L2=new JLabel("Weight in kg"); JLabel L3=new JLabel("Your Body Mass is"); JLabel L4=new JLabel("Your weight is"); JButton B=new JButton("Calculate Body Mass"); ImageIcon pic=new ImageIcon("body.jpg"); JLabel L5=new JLabel(pic); JMenu M=new JMenu("your mode"); JMenuItem m=new JMenuItem("MAGENTA"); JMenuItem k=new JMenuItem("CYAN"); JMenuItem o=new JMenuItem("ORANGE"); JMenuItem p=new JMenuItem("PINK"); JMenuBar bar=new JMenuBar(); bar.add(M); setJMenuBar(bar); P1.setLayout(W); P3.setLayout(W); L1.setOpaque(true); L1.setBackground(Color.ORANGE); L1.setForeground(Color.RED); L1.setFont(N); L2.setOpaque(true); L2.setBackground(Color.ORANGE); L2.setForeground(Color.RED); L2.setFont(N); L3.setOpaque(true); L3.setBackground(Color.ORANGE); L3.setForeground(Color.RED); L3.setFont(N); L4.setOpaque(true); L4.setBackground(Color.ORANGE); L4.setForeground(Color.RED); L4.setFont(N); B.setBackground(Color.PINK); B.setForeground(Color.GRAY); B.setFont(N); B.setToolTipText("Clic to calculate your body mass"); B.addActionListener(this); m.addActionListener(this); k.addActionListener(this); o.addActionListener(this); p.addActionListener(this); P1.add(L1); P1.add(T1); P1.add(L2); P1.add(T2); P1.add(B,BorderLayout.CENTER); P2.add(L5); P3.add(L3); P3.add(T3); P3.add(L4); P3.add(T4); M.add(m); M.add(k); M.add(o); M.add(p); } public void actionPerformed(ActionEvent ae) { double a=Double.parseDouble(T1.getText()); double b=Double.parseDouble(T2.getText()); T3.setText(Double.toString(b/((a/100)*(a/100)))); double c=Double.parseDouble(T3.getText()); if(c=16.5)&&(c=20)&&(c=25)&&(c=30)&&(cRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.