1. 程式人生 > >JAVA GUI 做一個學生資訊視窗

JAVA GUI 做一個學生資訊視窗

package gui;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.Icon;
import javax.swing.ImageIcon;
public class LabelFrame extends JFrame
{
    private final JLabel label1;
    private final JLabel label2;
    private
final JLabel label3; private final JLabel label4; public LabelFrame() { super("Student information"); setLayout(new FlowLayout()); label1 = new JLabel("Student name: Amy"); label1.setToolTipText("studentA"); add(label1); Icon photo = new ImageIcon(getClass().getResource( "photo.gif"
)); label2 = new JLabel("student photo:", photo,SwingConstants.RIGHT); label2.setHorizontalTextPosition(SwingConstants.LEFT); //Icon photo = new ImageIcon(getClass().getResource( "photo.gif")); add(label2); label3 = new JLabel("Student number: 123456"); label3.setToolTipText("123456"
); add(label3); label4 = new JLabel("Student major: CS"); add(label4); } public static void main(String[] args) { LabelFrame labelFrame = new LabelFrame(); labelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); labelFrame.setSize(260,180); labelFrame.setVisible(true); } }