[java]
package com.han;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.font.LineMetrics;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToggleButton;
import javax.swing.ScrollPaneConstants;
import javax.swing.Scrollable;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
/**
* @author HAN
*
*/
@SuppressWarnings("serial")
public class ScrollDemo extends JPanel implements ItemListener {
private JScrollPane scrollPane;
private Rule hRule;
private Rule vRule;
/**
* Create a placeholder icon, which consists in a white box with a black
* border and a red x inside. It's used to display something when there are
* issues loading an icon from an external location.
*
* @author HAN
*
*/
class MissingIcon implements Icon {
private int width = 32;
private int height = 32;
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
// TODO Auto-generated method stub
Graphics2D g2 = (Graphics2D) g;
Shape rect = new Rectangle2D.Double(x + 1, y + 1, width - 2,
height - 2);
g2.setColor(Color.WHITE);
g2.fill(rect);
g2.setColor(Color.BLACK);
g2.draw(rect);// By default, the stroke is 1.0f solid line.
g2.setColor(Color.RED);
BasicStroke stroke = new BasicStroke(4.0f);
g2.setStroke(stroke);
g2.draw(new Line2D.Double(x + 10, y + 10, x + width - 10, y
+ height - 10));
g2.draw(new Line2D.Double(x + 10, y + height - 10, x + width - 10,
y + 10));
}
@Override
public int getIconWidth() {
// TODO Auto-generated method stub
return width;
}
@Override
public int getIconHeight() {
// TODO Auto-generated method stub
return height;
}
}
public class Corner extends JComponent {
@Override
protected void paintComponent(Graphics g) {
g.setColor(new Color(230, 163, 4));
g.fillRect(0, 0, getWidth(), getHeight());
}
}
/**
* The enum type is more powerful than the traditional constants defining by
* encapsulate them in an inte易做图ce.
*
* @author HAN
*
*/
enum RuleConstants {
HORIZONTAL, VERTICAL
}
public class Rule extends JComponent {
private RuleConstants direction;
private String mode;
// Define the distance on screen for an inch and a centimeter.
final int INCH = Toolkit.getDefaultToolkit().getScreenResolution();
final int CM = (int) (INCH / 2.54);
private int preferredWidth;
private int preferredHeight;
private static final int SIZE = 35;
Rule(RuleConstants direction, String mode) {
this.direction = direction;
this.mode = mode;
}
private void setUni
补充:软件开发 , Java ,