MAKING A JFRAME THAT HAS SHAPES AND TEXT IN IT
import javax.swing.*;
class First{
public static void main(String args[]){
JFrame frame = new JFrame("Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Second s = new Second();
frame.add(s);
frame.setSize(400, 250);
frame.setVisible(true);
frame.setResizable(false);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Formatter;
import java.util.Scanner;
// Making a class that inherits JPanel methods etc.
public class Second extends JPanel {
// Creating a paintComponent method from JPanel libraries
public void paintComponent(Graphics g){
// Calling the super class component methods
super.paintComponent(g);
// Setting the background to WHITE
this.setBackground(Color.WHITE);
// Making a rectangle and setting its color to blue
g.setColor(Color.BLUE);
// Making the rectangle and positioning it and giving it proportions
g.fillRect(25, 25, 100, 30);
// Making a custom RGB colorw
g.setColor(new Color(215, 67, 53));
g.fillRect(25, 65,100, 30);
// Making colored text
g.setColor(Color.BLUE);
g.drawString("Colored Text", 25, 120);
}
}