0% found this document useful (0 votes)
39 views2 pages

Java Rafael D. Catain Activity # 1 BSIT-3 02/13/16

This document contains code for a Java application that displays labels with text and images. The main class y creates an instance of the appClass, which extends JFrame. The appClass constructor creates three JLabels, one with HTML text and an image, one with only text, and one with only an image. The labels are added to the frame with tooltips. The frame is configured and made visible, displaying the labeled content.

Uploaded by

RafaelCatain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Java Rafael D. Catain Activity # 1 BSIT-3 02/13/16

This document contains code for a Java application that displays labels with text and images. The main class y creates an instance of the appClass, which extends JFrame. The appClass constructor creates three JLabels, one with HTML text and an image, one with only text, and one with only an image. The labels are added to the frame with tooltips. The frame is configured and made visible, displaying the labeled content.

Uploaded by

RafaelCatain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

JAVA

Rafael D. Catain
BSIT-3

Activity # 1
02/13/16

/**
* @(#)y.java
*
* y application
*
* @Rafael D. Catain
* @version 1.00 2016/2/13
*/
public class y {
public static void main(String[] args) {
appClass x = new appClass()
}
}
************************************************************************************

/**
* @(#)appClass.java
*
*
* @Rafael D. Catain
* @version 1.00 2016/2/13
*/
import javax.swing.*;
public class appClass extends JFrame{
public appClass(){
JLabel label1,label2,label3;
ImageIcon icon = createImageIcon("/Resources/spidey3.gif","");
//Create the 1st label
label1 = new JLabel("<html>THE Eency WeEncy Spider<br><br>The eency
weency spider went up the water spout,<br>Down came the rain and washed the
spider out,<br>Out came the sun and dried up all the rain,<br>Now the eency
weency spider goes up the spout again", icon, JLabel.CENTER);
//Set the position
label1.setVerticalTextPosition(JLabel.BOTTOM);
label1.setVerticalTextPosition(JLabel.CENTER);
//Create the other label
label2 = new JLabel("Text-Only");
label3 = new JLabel(icon);
//Create Tool tips
label1.setToolTipText("A Label Containing both Image & ext");

label2.setToolTipText("A Label Containing Only Text");


label3.setToolTipText("A Label Containing Only an Image");
//add the labels
add(label1);
//add(label2);
//add(label3);
//Set up
setTitle("THE Eency WeEncy Spider");
setSize(200,300);
setLocation(100,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
protected ImageIcon createImageIcon(String path, String description) {
java.net.URL imgURL = getClass().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
}

You might also like