Please help me to fix this.
public static void main(String[] args) { JFrame f = new JFrame(); SchoolOption f1 = new SchoolOption(); Color c = new Color(128,0,0); Container con = f.getContentPane(); con.setBackground(c); f.setDefaultCloseOperation(JFrame.EXITONCLOSE); f.setSize(400, 120); f.setTitle("Bloomfield College Student Registration System "); f.setResizable(false); f.setLocationRelativeTo(null); f.setVisible(true); } }
print("public static void main(String[] args)
{
JFrame f = new JFrame();
SchoolOption f1 = new SchoolOption();
Color c = new Color(128,0,0);
Container con = f.getContentPane();
con.setBackground(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 120);
f.setTitle("Bloomfield College Student Registration System ");
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}");
For label you need to create and initialize the JLabel class object and add it to container. Inorder to do that you need to import javax.swing.* So the code must contain the following lines to add label and text field JLabel l1=new JLabel("Enter name"); JTextField tf1=new JTextField(10); con.add(l1); con.add(tf1);
I am very new to Java, I followed your instruction and this is what I came up with, am I missing something?
print("{
JFrame f = new JFrame();
JLabel l1 = new JLabel();
JTextField tf1 = new JTextField ();
SchoolOption f1 = new SchoolOption();
Color c = new Color(128,0,0);
Container con = f.getContentPane();
con.setBackground(c);
con.add(l1);
con.add(tf1);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 120);
f.setTitle("Bloomfield College Student Registration System");
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
l1.setVisible(true);
//tf1.setVisible(true)
}");
It has white background now instead of Maroon
import java.awt.*;
import javax.swing.*;
class Test{
public static void main(String[] args){
JFrame f = new JFrame();
JLabel l1 = new JLabel("Name: ");
JTextField tf1 = new JTextField ();
f.setLayout(null);
l1.setBounds(10,10,100,20);
tf1.setBounds(120,10,120,20);
SchoolOption f1 = new SchoolOption();
f.add(l1);
f.add(tf1);
Color c = new Color(128,0,0);
Container con = f.getContentPane();
con.setBackground(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 120);
f.setTitle("Bloomfield College Student Registration System");
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
l1.setVisible(true);
}
}
import java.awt.*;
import javax.swing.*;
class Test{
public static void main(String[] args){
JFrame f = new JFrame();
JLabel l1 = new JLabel("Name: ");
JTextField tf1 = new JTextField ();
f.setLayout(null);
l1.setBounds(10,10,100,20);
tf1.setBounds(120,10,120,20);
SchoolOption f1 = new SchoolOption();
f.add(l1);
f.add(tf1);
Color c = new Color(128,0,0);
Container con = f.getContentPane();
con.setBackground(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 120);
f.setTitle("Bloomfield College Student Registration System");
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
l1.setVisible(true);
}
}
import java.awt.*;
import javax.swing.*;
class Test{
public static void main(String[] args){
JFrame f = new JFrame();
JLabel l1 = new JLabel("Name: ");
JTextField tf1 = new JTextField ();
f.setLayout(null);
l1.setBounds(10,10,100,20);
tf1.setBounds(120,10,120,20);
SchoolOption f1 = new SchoolOption();
f.add(l1);
f.add(tf1);
Color c = new Color(128,0,0);
Container con = f.getContentPane();
con.setBackground(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 120);
f.setTitle("Bloomfield College Student Registration System");
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
l1.setVisible(true);
}
}
import java.awt.*;
import javax.swing.*;
class Test{
public static void main(String[] args){
JFrame f = new JFrame();
JLabel l1 = new JLabel("Name: ");
JTextField tf1 = new JTextField ();
f.setLayout(null);
l1.setBounds(10,10,100,20);
tf1.setBounds(120,10,120,20);
SchoolOption f1 = new SchoolOption();
f.add(l1);
f.add(tf1);
Color c = new Color(128,0,0);
Container con = f.getContentPane();
con.setBackground(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 120);
f.setTitle("Bloomfield College Student Registration System");
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
l1.setVisible(true);
}
}