?? buttonarrowicon.java
字號:
/*
* PSwing Utilities -- Nifty Swing Widgets
* Copyright (C) 2002 Pallas Technology
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Pallas Technology
* 1170 HOWELL MILL RD NW
* SUITE 306
* ATLANTA GEORGIA 30318
*
* PHONE 404.983.0623
* EMAIL info@pallastechnology.com
*
* www.pallastechnology.com
**************************************************************************
* $Archive: SwingTools$
* $FileName: ButtonArrowIcon.java$
* $FileID: 23$
*
* Last change:
* $AuthorName: Rob MacGrogan$
* $Date: 2/10/03 5:07 PM$
* $VerID: 65$
* $Comment: $
**************************************************************************/
package com.pallas.swing.spinner;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* Title: $FileName: ButtonArrowIcon.java$
* @version $VerNum: 2$
* @author $AuthorName: Rob MacGrogan$<br><br>
*
* $Description: Left/Right arrow icon.$<br>
* $KeyWordsOff: $<br><br>
*/
public class ButtonArrowIcon implements Icon {
public static final int LEFT = 1;
public static final int RIGHT = 2;
protected int direction;
protected int width = 8;
protected int height = 8;
public ButtonArrowIcon(int direction) {
this.direction = direction;
}
public int getIconWidth() {
return width;
}
public int getIconHeight() {
return height;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
Color bg = c.getBackground();
Color light = bg.darker();
Color shade = bg.brighter();
int w = width;
int h = height;
int m = h / 2;
if (direction == LEFT) {
Polygon triangle = new Polygon();
triangle.addPoint(x, y + m);
triangle.addPoint(x + w, y);
triangle.addPoint(x + w, y + h);
g.setColor(Color.BLACK);
g.fillPolygon(triangle);
g.setColor(light);
g.drawLine(x, y + m, x + w, y);
g.drawLine(x, y + m, x + w, y + h);
g.setColor(shade);
g.drawLine(x + w, y, x + w, y + h);
}
if (direction == RIGHT) {
Polygon triangle = new Polygon();
triangle.addPoint(x, y);
triangle.addPoint(x, y + h);
triangle.addPoint(x + w, y + m);
g.setColor(Color.BLACK);
g.fillPolygon(triangle);
g.setColor(light);
g.drawLine(x, y, x, y + h);
g.drawLine(x, y, x + w, y + m);
g.setColor(shade);
g.drawLine(x, y + h, x + w, y + m);
}
}
public static void main(String[] args){
try{
JFrame frame = new JFrame();
JButton btnL = new JButton(new ButtonArrowIcon(LEFT));
JButton btnR = new JButton(new ButtonArrowIcon(RIGHT));
JPanel panel = new JPanel();
panel.add(btnL);
panel.add(btnR);
frame.getContentPane().add(panel);
frame.addWindowListener
(new
WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
}//end anon class
);
Dimension sd = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
int width = 350;
int height = 150;
int x = (sd.width - width) / 2;
int y = (sd.height - height) /2;
frame.setBounds(x, y, width, height);
//setLookAndFeel();
frame.setVisible(true);
}
catch (Throwable thr){
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -