当前位置 : 主页 > 手机开发 > harmonyos >

Java_swing_边框简单实现

来源:互联网 收集:自由互联 发布时间:2023-08-26
-效果 -源码 //: Show.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;/** * // 显示框架 * @author cyb_23 */public class Show {/** * 框架 * @param jp * @param width * @param height */public static void inFrame(JPa


->效果

Java_swing_边框简单实现_java


->源码

//: Show.java


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * // 显示框架
 * @author cyb_23
 */
public class Show {
	
	/**
	 * 框架
	 * @param jp
	 * @param width
	 * @param height
	 */
	public static void inFrame(JPanel jp, int width, int height) {
		// 框架标题
		String title = jp.getClass().toString();
		if (title.indexOf("class") != -1){
			title = title.substring(6);
		}
			
		// 框架
		JFrame frame = new JFrame(title);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		frame.getContentPane().add(jp, BorderLayout.CENTER);
		frame.setSize(width, height);
		frame.setVisible(true);
	}
} // /:~



//: Borders.java
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 * Swing边框
 * @author cyb_23
 */
public class Borders extends JPanel {
	
	/**
	 * 显示边框的面板
	 * @param b
	 * @return JPanel
	 */
	static JPanel showBorder(Border b) {
		JPanel jp = new JPanel();
		jp.setLayout(new BorderLayout());
		
		String nm = b.getClass().toString();
		nm = nm.substring(nm.lastIndexOf('.') + 1);
		jp.add(new JLabel(nm, JLabel.CENTER), BorderLayout.CENTER);
		jp.setBorder(b);
		
		return jp;
	}

	/**
	 * 构造函数
	 */
	public Borders() {
		setLayout(new GridLayout(2, 4));
		
		add(showBorder(new TitledBorder("Title")));
		add(showBorder(new EtchedBorder()));
		add(showBorder(new LineBorder(Color.blue)));
		add(showBorder(new MatteBorder(5, 5, 30, 30, Color.green)));
		add(showBorder(new BevelBorder(BevelBorder.RAISED)));
		add(showBorder(new SoftBevelBorder(BevelBorder.LOWERED)));
		add(showBorder(new CompoundBorder(new EtchedBorder(), new LineBorder(Color.red))));
	}

	public static void main(String args[]) {
		Show.inFrame(new Borders(), 500, 300);
	}
} ///:~




【本文转自:国外高防服务器 http://www.558idc.com/usa.html转载请说明出处】
上一篇:Web_XP_IIS_“服务器应用程序不可用”问题;
下一篇:没有了
网友评论