📄 banner.java
字号:
package com.vimas.interfaceapplet.buttons;
import java.awt.*;
import java.awt.event.*;
//import java.net.*;
import java.applet.*;
//import java.awt.image.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Vimas technologies</p>
* @author miha
* @version 1.0
*/
public class Banner extends Component
{
String path=null;
int x=20,y=20;
Image image=null;
// static int capWidth = 20; // The width of the Button's endcap
protected boolean pressed = false; // true if the button is detented.
ActionListener actionListener; // Post action events to listeners
String label=null;
//String url;
//String target;
// protected boolean isEnabled =true;
//******************************************************************************
public Banner(String image, int w, int h)
{
this.x=w;
this.y=h;
this.path=image;
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
//******************************************************************************
public Banner(String label)
{
this.label=label;
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
//******************************************************************************
public void paint(Graphics g)
{
if(label==null)
{
g.setColor(this.getBackground());
g.drawImage(image, 4, 4, this);
}
else
{
g.setColor(Color.blue);
int width = getSize().width - 1;
int height = getSize().height - 1;
Font f = getFont();
if(f != null) {
FontMetrics fm = getFontMetrics(getFont());
g.drawString(label,
width/2 - fm.stringWidth(label)/2,
height/2 + fm.getHeight()/2 - fm.getMaxDescent()
);
}
}
}
//*****************************************************************************
public void loadImage(Applet a)
{
image = a.getImage(a.getCodeBase(), path);
this.setBackground(a.getBackground());
}
//*****************************************************************************
public Dimension getPreferredSize()
{
//text banner
if(label!=null)
{
Font f = getFont();
if (f != null)
{
FontMetrics fm = getFontMetrics(getFont());
return new Dimension(fm.stringWidth(label) + 10, fm.getHeight());
}
}
else //image banner
return new Dimension(x, y);
return new Dimension(10, 10);
}
//*****************************************************************************
public Dimension getMinimumSize() {
return new Dimension(x, y);
}
//*****************************************************************************
public void addActionListener(ActionListener listener) {
actionListener = AWTEventMulticaster.add(actionListener, listener);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
//*****************************************************************************
public void removeActionListener(ActionListener listener) {
actionListener = AWTEventMulticaster.remove(actionListener, listener);
}
//*****************************************************************************
public void processMouseEvent(MouseEvent e) {
Cursor cur;
//Graphics g;
switch(e.getID())
{
case MouseEvent.MOUSE_PRESSED:
pressed=true;
break;
case MouseEvent.MOUSE_RELEASED:
if(actionListener != null)
{
actionListener.actionPerformed(new ActionEvent(
this, ActionEvent.ACTION_PERFORMED,""));
}
if(pressed == true) pressed = false;
break;
case MouseEvent.MOUSE_ENTERED:
//System.out.println("over");
cur=new Cursor(Cursor.HAND_CURSOR);
this.setCursor(cur);
break;
case MouseEvent.MOUSE_EXITED:
//System.out.println("exit");
if (pressed == true)
{
pressed = false;
}
cur=new Cursor(Cursor.DEFAULT_CURSOR);
this.setCursor(cur);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -