import java.awt.*; import javax.swing.*; import javax.swing.border.*; /** a little application that does a simple example demo of Swing borders, inspired and extended from the jshell in-class demo in CS 235 - Week 6 lecture on 2021-09-27 @author Sharon Tuttle @version 2021-09-28 */ public class SimpleBorderDemo { /** throws up a JFrame with a couple of components that have simple borders added @param args not used here */ public static void main(String[] args) { JFrame playFrame = new JFrame(); playFrame.setSize(600, 400); // more on this next week: changing JFrame's // default layout manager playFrame.setLayout(new GridLayout(2, 1)); // here is a JPanel with a JLabel, neither with // borders added JPanel myPanel1 = new JPanel(); JLabel myLabel1 = new JLabel("A Beautiful long JLabel " + "with NO border"); myLabel1.setFont(new Font("SanSerif", Font.PLAIN, 20)); myLabel1.setForeground(Color.BLUE); myPanel1.add(myLabel1); playFrame.add(myPanel1); // here is a JPanel with a JLabel that do have // borders added JPanel myPanel2 = new JPanel(); // adding a border to myPanel2 myPanel2.setBorder(new TitledBorder(new EtchedBorder(), "I am a JPanel Border!")); JLabel myLabel2 = new JLabel("A Beautiful long JLabel " + "for showing off a Border"); myLabel2.setFont(new Font("SanSerif", Font.PLAIN, 20)); myLabel2.setForeground(Color.BLUE); // adding a border to myLabel2 myLabel2.setBorder(new TitledBorder(new EtchedBorder(), "I am a JLabel's Border")); myPanel2.add(myLabel2); playFrame.add(myPanel2); playFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); playFrame.setVisible(true); } }