Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an individual program of your choosing. You decide what problem you want t

ID: 3769675 • Letter: W

Question

Write an individual program of your choosing. You decide what problem you want to solve and write the program to solve it. It must include a written description of what the program does and instructions about how the program works in the comments section. I do not want to see a program from the text, but all of you have interests and hobbies that you could design a program that would meet the following criteria.

-Comments: Enough so another programmer will know what the program is doing without even reading your description Also, include your name, date, and program name at the top of the program

-Selection structure: Include either If/else logic or a case structure

-Repetition structure: Include either While, Do While or For loop Array Any type of an array

-Inheritance: Use Inheritance and/or Interfaces

-Exception: Use try…catch block

-Components: Button, TextField, Label, or ComboBox

-Theme: There must be some point to your program, not just a collection of components

-Receives user input

-Performs output

-Add a graphic or color

To receive full credit you will design a JFrame Application that contains at least 4 of the 6, (selection, loop, array, inheritance, components or exception) plus all of the others mentioned above

Explanation / Answer

I gave you two examples.

This is an example for for displaying java and j2ee.

import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel { // here inheritance
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setFont(new Font("Serif", Font.PLAIN, 48));
paintHorizontallyCenteredText(g2, "Java Source", 200, 75);
paintHorizontallyCenteredText(g2, "and", 200, 125);
paintHorizontallyCenteredText(g2, "Support", 200, 175);
}
protected void paintHorizontallyCenteredText(Graphics2D g2,
String s, float centerX, float baselineY) {
FontRenderContext frc = g2.getFontRenderContext();
Rectangle2D bounds = g2.getFont().getStringBounds(s, frc); //here is a component
float width = (float) bounds.getWidth();
g2.drawString(s, centerX - width / 2, baselineY);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.getContentPane().add(new Main());
f.setSize(450, 350);
f.setVisible(true);
}
}

Here is a simple example.

import java.awt.*;

import javax.swing.*;

class ButtonFrame extends JFrame // inheritance
{
JButton bChange ; // reference to the button object

// constructor for ButtonFrame
ButtonFrame(String title)
{
super( title ); // invoke the JFrame constructor
setLayout( new FlowLayout() ); // set the layout manager

bChange = new JButton("Click Me!"); // construct a JButton here is a component
add( bChange ); // add the button to the JFrame
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
}
}

public class ButtonDemo
{
public static void main ( String[] args )
{

try //exception

{
ButtonFrame frm = new ButtonFrame("Button Demo");

}

catch(Exception e) { };

int size =8;

if(size <7) //selection

frm.setSize( 150, 75 );

else

frm.setSize(175,80);   
frm.setVisible( true );   
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote