181k views
1 vote
Create an application with a JFrame and at least 5 labels that contain interesting historical facts. Add the labels to the frame, but use a different font for each label. Also, include a JTextField so the user can type in their own interesting fact. Save the file as JHistoricalFacts.java Upload or copy the java file into the dropbox and submit.

User ErTR
by
8.7k points

1 Answer

4 votes

Final answer:

The task is to create a Java application using Swing, with a JFrame containing 5 labels with historical facts, each in a different font, and a JTextField for user input.

Step-by-step explanation:

To fulfill the requirement of creating an application with a JFrame and at least 5 labels containing interesting historical facts, you would need to write a Java program using the Swing framework. Each label would need to have a unique font set to it, showcasing different styles for each historical fact presented. Additionally, the inclusion of a JTextField allows users to input their own facts.

Your code outline would look something like this:


import javax.swing.*;
import java.awt.*;

public class JHistoricalFacts extends JFrame {
public JHistoricalFacts() {
setTitle("Historical Facts");
setLayout(new FlowLayout());

// Create the labels with historical facts
JLabel label1 = new JLabel("Fact 1");
label1.setFont(new Font("Serif", Font.BOLD, 12));
add(label1);

JLabel label2 = new JLabel("Fact 2");
label2.setFont(new Font("Arial", Font.ITALIC, 14));
add(label2);

// ... Create more labels with different fonts

// Create the text field for user input
JTextField userFact = new JTextField(20);
add(userFact);

// Setting the frame size and behavior
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

public static void main(String[] args) {
new JHistoricalFacts();
}
}

User ColinM
by
8.6k points