
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document is about swing in java and it can help to your exams or assignments
Typology: Lab Reports
1 / 1
This page cannot be seen from the preview
Don't miss anything!

//import swing library import java.awt.; import javax.swing.; public class oop_exer { public static void main(String[] args) { //create the frame JFrame fr = new JFrame("OOP Exercise 1"); //set frame size fr.setSize(250,100); //set frame visibility fr.setVisible(true); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //create font Font fnt = new Font("Comic Sans MS",Font.BOLD,24); Font fnt1 = new Font("Comic Sans MS",Font.ITALIC,24); //create labels JLabel lbl1 = new JLabel("Hello"); lbl1.setForeground(Color.RED); lbl1.setFont(fnt); JLabel lbl2 = new JLabel(); lbl2.setText("Hi!"); lbl2.setForeground(Color.GREEN); lbl2.setFont(fnt1); //set location of the labels lbl1.setBounds(10, 5, 100, 25); lbl2.setBounds(130, 5, 100, 25); //place the labels on the frame fr.add(lbl1); fr.add(lbl2); } }