JavaScript Swing core java GUI, Lab Reports of Java Programming

This document is about swing in java and it can help to your exams or assignments

Typology: Lab Reports

2020/2021

Uploaded on 04/01/2022

zurbito-jacque-landrito
zurbito-jacque-landrito 🇵🇭

5 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
//import swing library
import java.awt.*;
import javax.swing.*;
public class oop_exer1
{
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);
}
}

Partial preview of the text

Download JavaScript Swing core java GUI and more Lab Reports Java Programming in PDF only on Docsity!

//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); } }