TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
效果图:

- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.font.FontRenderContext;
- import java.awt.geom.AffineTransform;
- import javax.swing.Icon;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import sun.security.action.GetPropertyAction;
- public class BackwardsJLabel extends JLabel {
-
- public BackwardsJLabel () { super(); }
- public BackwardsJLabel (Icon image) {super (image);}
- public BackwardsJLabel (Icon image, int align) {super (image, align);}
- public BackwardsJLabel (String text) { super (text);}
- public BackwardsJLabel (String text, Icon icon, int align) {
- super (text, icon, align);
- }
- public BackwardsJLabel (String text, int align) {
- super (text, align);
- }
- public void paint (Graphics g) {
- if (g instanceof Graphics2D) {
- Graphics2D g2 = (Graphics2D) g;
- AffineTransform flipTrans = new AffineTransform();
- double widthD = (double) getWidth();
- flipTrans.setToTranslation (widthD, 0);
- flipTrans.scale (-1.0, 1);
- g2.transform (flipTrans);
- super.paint(g);
- } else {
- super.paint(g);
- }
- }
- public static void main (String[] args) {
- BackwardsJLabel field =
- new BackwardsJLabel ("谁能到懂我说的话?能看懂的赶紧留帖!!");
- field.setFont(new Font("宋体",0,12));
- JFrame frame = new JFrame("颠倒的JLabel");
- frame.getContentPane().add (field);
- frame.pack();
- frame.setVisible(true);
- }
- }
复制代码
源码下载:http://file.javaxxz.com/2014/11/18/235742000.zip |
|