📄 simplechoice.java
字号:
/*
$Author: $
$Date: $
$Revision: $
$NoKeywords: $
*/
package jp.co.ntl.awt;
/*
public class SimpleChoice extends Component implements ListChoiceCommon {
private PopupMenu popupMenu;
private MenuItem[] menuItems;
public void addItem(String item) {}
public void add(String item) {}
public void select(String item) {}
public void select(int index) {}
public int getSelectedIndex() { return 0; }
public String getSelectedItem() { return ""; }
public void removeAll() {}
public void addItemListener(ItemListener listener) {}
public SimpleChoice() {
super();
popupMenu = new PopupMenu();
menuItems = new MenuItem[5];
for (int i = 0; i < menuItems.length; i++) {
menuItems[i] = new MenuItem("" + i);
popupMenu.add(menuItems[i]);
}
add(popupMenu);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
public void processMouseEvent(MouseEvent me) {
int id = me.getID();
if (id == MouseEvent.MOUSE_PRESSED && contains(me.getPoint())) {
Rectangle r = getBounds();
popupMenu.show(this, 0, r.height);
}
super.processMouseEvent(me);
}
public void paint(Graphics g) {
Dimension d = getSize();
g.setColor(Color.white);
g.fillRect(0, 0, d.width, d.height);
// 榞
g.setColor(Color.darkGray);
g.drawLine(0, 0, 0, d.height - 2);
g.drawLine(0, 0, d.width - 2, 0);
g.setColor(Color.white);
g.drawLine(d.width - 1, 0, d.width - 1, d.height);
g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
g.setColor(Color.gray);
g.drawLine(1, 1, 1, d.height - 3);
g.drawLine(1, 1, d.width - 3, 1);
g.setColor(Color.lightGray);
g.drawLine(d.width - 2, 1, d.width - 2, d.height - 2);
g.drawLine(1, d.height - 2, d.width - 2, d.height - 2);
// 僽儘僢僋
int baseX = d.width - (d.height - 4 + 2);
int baseY = 2;
int length = d.height - 4;
g.setColor(getBackground());
g.fillRect(baseX, baseY, length, length);
g.setColor(Color.darkGray);
g.drawLine(baseX, baseY + length - 1, baseX + length - 1, baseY + length - 1);
g.drawLine(baseX + length - 1, baseY, baseX + length - 1, baseY + length - 1);
g.setColor(Color.white);
g.drawLine(baseX + 1, baseY + 1, baseX + 1, baseY + length - 3);
g.drawLine(baseX + 1, baseY + 1, baseX + length - 3, baseY + 1);
g.setColor(Color.gray);
g.drawLine(baseX + length - 2, baseY + 1, baseX + length - 2, baseY + length - 2);
g.drawLine(baseX + 1, baseY + length - 2, baseX + length - 2, baseY + length - 2);
// 栴報
int x = baseX + (length - 5) / 2;
int y = baseY + length / 2;
g.setColor(Color.black);
g.drawLine(x, y, x + 4, y);
x += 1; y += 1;
g.drawLine(x, y, x + 2, y);
x += 1; y += 1;
g.drawLine(x, y, x + 0, y);
}
}
*/
public class SimpleChoice extends java.awt.Choice implements ListChoiceCommon {
/**
*
*/
private static final long serialVersionUID = 1L;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -