-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'dmmxzz/master'
- Loading branch information
Showing
13 changed files
with
874 additions
and
101 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.lottery.component; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* Created by tasly on 2014/10/22. | ||
*/ | ||
public class ApplicationConfig { | ||
public static Color COLOR_PANEL_BACKGROUND = new Color(224, 235, 247); //충겼교쒼 | ||
public static Color COLOR_UI_TEXT = new Color(116, 185, 235); //UI匡俚奈 | ||
public static Color COLOR_UI_FRAME = new Color(255, 183, 0);//UI긋움奈(뼝) | ||
public static Color COLOR_TOOLBAR_FRAME = new Color(186, 201, 219); //묏야으긋움 | ||
public static Font FONT_UI_TEXT = new Font("菓흡錤붚", Font.PLAIN, 14); //UI俚竟 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.lottery.component; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.MouseEvent; | ||
|
||
/** | ||
* Created by tasly on 2014/10/22. | ||
*/ | ||
public class CrystalComponent extends JButton { | ||
protected boolean isMouseEntered; // Êó±ê½øÈë±êÖ¾ | ||
|
||
public CrystalComponent() { | ||
this.addMouseListener(new CrystalComponentMouseListenr(this)); | ||
} | ||
|
||
public void mouseClicked(MouseEvent e) { | ||
} | ||
|
||
public void mouseEntered(MouseEvent e) { | ||
} | ||
|
||
public void mouseExited(MouseEvent e) { | ||
} | ||
|
||
public void mousePressed(MouseEvent e) { | ||
} | ||
|
||
public void mouseReleased(MouseEvent e) { | ||
|
||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/com/lottery/component/CrystalComponentMouseListenr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.lottery.component; | ||
|
||
import java.awt.*; | ||
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseListener; | ||
|
||
/** | ||
* Created by tasly on 2014/10/22. | ||
*/ | ||
public class CrystalComponentMouseListenr implements MouseListener { | ||
private CrystalComponent crystalComponent; | ||
|
||
public CrystalComponentMouseListenr(CrystalComponent crystalComponent) { | ||
this.crystalComponent = crystalComponent; | ||
} | ||
|
||
public void mouseClicked(MouseEvent e) { | ||
crystalComponent.mouseClicked(e); | ||
crystalComponent.updateUI(); | ||
} | ||
|
||
public void mouseEntered(MouseEvent e) { | ||
crystalComponent.mouseEntered(e); | ||
crystalComponent.isMouseEntered = true; | ||
crystalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); | ||
crystalComponent.updateUI(); | ||
|
||
} | ||
|
||
public void mouseExited(MouseEvent e) { | ||
crystalComponent.mouseExited(e); | ||
crystalComponent.isMouseEntered = false; | ||
crystalComponent.setCursor(Cursor.getDefaultCursor()); | ||
crystalComponent.updateUI(); | ||
} | ||
|
||
public void mousePressed(MouseEvent e) { | ||
crystalComponent.mousePressed(e); | ||
crystalComponent.updateUI(); | ||
} | ||
|
||
public void mouseReleased(MouseEvent e) { | ||
crystalComponent.mouseReleased(e); | ||
crystalComponent.updateUI(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.lottery.component; | ||
|
||
import java.awt.*; | ||
import java.awt.event.MouseEvent; | ||
|
||
/** | ||
* Created by tasly on 2014/10/22. | ||
*/ | ||
public class CrystalImageButton extends ImageButton { | ||
private int frameType = 0; // 边框 | ||
public static int FRAME_RIGHT = 1; | ||
public static int FRAME_AROUND = 4; | ||
|
||
private int mbStatus = 0;// 鼠标事件状态 0: 鼠标弹起,1:鼠标按下 | ||
private boolean clicked = false; // 按下 | ||
|
||
private float alpha = 1f; // 不透明 | ||
|
||
public CrystalImageButton(String name) { | ||
setName(name); | ||
setOpaque(false); | ||
setBorderPainted(false); | ||
} | ||
|
||
public void mouseEntered(MouseEvent e) { | ||
if (clicked) | ||
return; | ||
new Thread() { | ||
public void run() { | ||
float a = 0f; | ||
while (a <= 1f) { | ||
alpha = a; | ||
CrystalImageButton.this.repaint(); | ||
try { | ||
Thread.sleep(50); | ||
} catch (InterruptedException e) { | ||
} | ||
a += 0.1; | ||
} | ||
} | ||
}.start(); | ||
} | ||
|
||
public void mouseExited(MouseEvent e) { | ||
} | ||
|
||
public int getFrameType() { | ||
return frameType; | ||
} | ||
|
||
public void setFrameType(int frameType) { | ||
this.frameType = frameType; | ||
} | ||
|
||
public void paintComponent(Graphics g) { | ||
Graphics2D g2 = (Graphics2D) g; | ||
AlphaComposite composite = AlphaComposite.getInstance( | ||
AlphaComposite.SRC_OVER, alpha); | ||
g2.setComposite(composite); | ||
|
||
// 绘制边框 | ||
if (this.isMouseEntered) { | ||
PaintUtils.drawButtonBackground(g2, this, new Color(253, 236, 219), | ||
new Color(253, 223, 187), new Color(255, 206, 105), | ||
new Color(255, 255, 222)); | ||
} | ||
// 按钮被按下的效果 | ||
if (clicked) { | ||
PaintUtils.drawButtonBackground(g2, this, new Color(255, 199, 99), | ||
new Color(253, 236, 219), new Color(253, 236, 219), | ||
new Color(255, 199, 99)); | ||
} | ||
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f); | ||
g2.setComposite(composite); | ||
if (frameType == FRAME_AROUND) { | ||
g.setColor(ApplicationConfig.COLOR_TOOLBAR_FRAME); | ||
g.drawRoundRect(1, 1, getWidth() - 4, getHeight() - 2, 3, 3); | ||
} else if (frameType == FRAME_RIGHT) { | ||
g.setColor(ApplicationConfig.COLOR_TOOLBAR_FRAME); | ||
g.drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 2); | ||
} | ||
|
||
// 消除锯齿 | ||
PaintUtils.setFractionalmetricsOn(g2); | ||
// 文字风格 | ||
g.setColor(ApplicationConfig.COLOR_UI_TEXT); | ||
g.setFont(ApplicationConfig.FONT_UI_TEXT); | ||
|
||
// 绘制图标 | ||
if (getImage() != null) { | ||
g.drawImage(getImage(), | ||
(getWidth() - getImage().getWidth(this)) / 2, 5 + mbStatus, | ||
this); | ||
g.drawString(getName(), (getWidth() - getName().length() | ||
* ApplicationConfig.FONT_UI_TEXT.getSize()) / 2, | ||
getImage().getHeight(this) + mbStatus); | ||
} else { | ||
g.drawString(getName(), (getWidth() - getName().length() | ||
* ApplicationConfig.FONT_UI_TEXT.getSize()) / 2, 10 + mbStatus); | ||
} | ||
} | ||
|
||
public void pushButton(boolean x) { | ||
clicked = x; | ||
} | ||
|
||
public void mousePressed(MouseEvent e) { | ||
mbStatus = 1; | ||
} | ||
|
||
public void mouseReleased(MouseEvent e) { | ||
mbStatus = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.lottery.component; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* Created by tasly on 2014/10/22. | ||
*/ | ||
public class ImageButton extends CrystalComponent { | ||
private String name; //Ãû³Æ | ||
private Image image; //ͼ±ê | ||
|
||
public Image getImage() { | ||
return image; | ||
} | ||
|
||
public void setImage(Image image) { | ||
this.image = image; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.lottery.component; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
/** | ||
* Created by tasly on 2014/10/21. | ||
*/ | ||
public class MemoryPanel extends JPanel { | ||
//状态条的颜色 | ||
private Color edgeColor = new Color(82, 115, 214); | ||
private Color centerColor = new Color(180, 200, 230); | ||
|
||
public void paint(Graphics g) { | ||
super.paint(g); | ||
//得到当前组件(JPanel)的大小 | ||
Dimension dimension = getSize(); | ||
//得到各边框的宽度 | ||
Insets insets = getInsets(); | ||
int left = insets.left; | ||
int top = insets.top; | ||
//得到内存使用状态信息 | ||
Runtime runtime = Runtime.getRuntime(); | ||
long freeMemory = runtime.freeMemory(); | ||
long totalMemory = runtime.totalMemory(); | ||
//组件(JPanel)除去左、右边框后的宽度 | ||
int insideWidth = dimension.width - (insets.left + insets.right); | ||
//内存使用量的显示宽度 | ||
int usedAmount = insideWidth - (int) (((long) insideWidth * freeMemory) / totalMemory); | ||
int insideHeight = dimension.height - (insets.bottom + insets.top); | ||
Graphics2D g2 = (Graphics2D) g; | ||
//设置渐变效果的画笔 | ||
g2.setPaint(new GradientPaint(left, top, edgeColor, left, insideHeight / 2, centerColor, true)); | ||
g.fillRect(left, top, usedAmount, insideHeight); | ||
g.setColor(getBackground()); | ||
g.fillRect(left + usedAmount, top, insideWidth - usedAmount, insideHeight); | ||
g.setFont(getFont()); | ||
g.setColor(Color.black); | ||
//显示状态的文字 | ||
String memory = (Long.toString((totalMemory - freeMemory) / 1048576L) + "M of " + Long.toString(totalMemory / 1048576L) + 'M'); | ||
//确定文字的显示位置 | ||
FontMetrics fontmetrics = g.getFontMetrics(); | ||
int stringWidth = fontmetrics.charsWidth(memory.toCharArray(), 0, memory.length()); | ||
int stringHeight = fontmetrics.getHeight() - fontmetrics.getDescent(); | ||
//显示文字 | ||
g.drawString(memory, left + (insideWidth - stringWidth) / 2, top + (insideHeight + stringHeight) / 2); | ||
} | ||
} |
Oops, something went wrong.