📄 aboutpanel.java
字号:
protected void startTimer() { final Runnable scroller = new Runnable() { public void run() { yOffset--; ScrollingCreditsPanel.this.repaint(); } }; TimerTask paintCredits = new TimerTask() { public void run() { EventQueue.invokeLater(scroller); } }; timer = new Timer(); timer.schedule(paintCredits, 500, 40); } protected void ensureTimerRunning() { if (timer == null) { startTimer(); } } private int yOffset; int count = 0; public void paintComponent(Graphics g) { super.paintComponent(g); int width = getWidth(); int height = getHeight(); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); Graphics2D g2d = (Graphics2D)g; g2d.setPaint(new GradientPaint(0, height / 2, Color.LIGHT_GRAY, width / 6, height / 2, Color.WHITE)); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.fillRect(0, 0, width, height); int x = 0; int y = 0; int stringWidth = 0; //g.setColor(Color.GRAY.brighter()); //g.drawLine(width / 6, 0, width / 6, height); g.setColor(Color.BLACK); for (int i = 0; i < names.length; i++) { g.setFont(nameFont); FontMetrics fm = g.getFontMetrics(); stringWidth = fm.stringWidth(names[i]); x = (width - stringWidth) / 2; y += fm.getHeight() + 1; g.drawString(names[i], x, y + yOffset + height); g.setFont(titleFont); fm = g.getFontMetrics(); stringWidth = fm.stringWidth(titles[i]); x = (width - stringWidth) / 2; y += fm.getHeight() + 1; g.drawString(titles[i], x, y + yOffset + height); if (i == names.length - 1) { //if (y + yOffset + height == 0) { if (Math.abs(yOffset) >= (y+ height)) { yOffset = 0; } } y += 15; } } public void stopTimer() { if (timer != null) { timer.cancel(); } timer = null; } } class AboutImagePanel extends JPanel { private static final int HEIGHT = 180; private static final int WIDTH = 350; private Timer timer; private Image eqImage; private Image eqText; private Image background; private Font versionFont; private String versionText; boolean stageOneComplete; boolean stageTwoComplete; boolean stageThreeComplete; boolean stageFourComplete; int leftOffsetImage; int leftOffsetText; int bottomOffsetVersion; private float alpha; private Color darkColour; private Color lightColour; protected AboutImagePanel() { stageOneComplete = false; stageTwoComplete = false; stageThreeComplete = false; stageFourComplete = false; leftOffsetImage = 0; leftOffsetText = 0; alpha = 0.0f; darkColour = new Color(124, 125, 203); lightColour = new Color(163,164,235); versionText = "Version " + System.getProperty("executequery.major.version"); versionFont = new Font("dialog", Font.PLAIN, 12); ImageIcon icon = GUIUtilities.loadImage("AboutImage.png"); eqImage = icon.getImage(); ImageIcon backgroundIcon = GUIUtilities.loadImage("AboutBackground.png"); background = backgroundIcon.getImage(); icon = GUIUtilities.loadImage("AboutText.png"); eqText = icon.getImage(); final Runnable fader = new Runnable() { public void run() { if (!stageOneComplete) { if (alpha >= 0.999f) stageOneComplete = true; else alpha += 0.020f; } if (stageOneComplete && !stageTwoComplete) { if (leftOffsetImage >= 90) stageTwoComplete = true; else leftOffsetImage += 1; } if (stageTwoComplete && !stageThreeComplete) { // 180 if (leftOffsetText >= 200) stageThreeComplete = true; else leftOffsetText += 2; } if (stageThreeComplete && !stageFourComplete) { if (bottomOffsetVersion >= 20) { // 15 stageFourComplete = true; timer.cancel(); GUIUtils.scheduleGC(); return; } else bottomOffsetVersion += 1; } AboutImagePanel.this.repaint(); } }; TimerTask paintImage = new TimerTask() { public void run() { EventQueue.invokeLater(fader); } }; timer = new Timer(); timer.schedule(paintImage, 500, 40); } public void stopTimer() { if (timer != null) { timer.cancel(); } } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; int imageWidth = eqImage.getWidth(this); int imageHeight = eqImage.getHeight(this); int imageX = (WIDTH - imageWidth) / 2; int imageY = (HEIGHT - imageHeight) / 2; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); AlphaComposite ac = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha); g2d.setComposite(ac); /* g2d.setPaint(new GradientPaint(WIDTH / 2, 0, darkColour, WIDTH / 2, HEIGHT, lightColour)); g2d.fillRect(0, 0, WIDTH, HEIGHT); */ g2d.drawImage(background, 0, 0, WIDTH, HEIGHT, this); g2d.drawImage(eqImage, imageX - leftOffsetImage - 1, imageY - 1, this); if (stageTwoComplete) { imageWidth = eqText.getWidth(this); imageHeight = eqText.getHeight(this); imageX = WIDTH - leftOffsetText; imageY = 115;//130; g2d.setClip(imageX - 1, imageY, WIDTH - imageX, imageHeight + 1); g2d.drawImage(eqText, imageX, imageY, this); } if (stageThreeComplete) { g2d.setColor(Color.WHITE); g2d.setFont(versionFont); FontMetrics fm = g.getFontMetrics(versionFont); int textLength = fm.stringWidth(versionText); imageX = imageX + ((imageWidth - textLength) / 2); g2d.setClip(imageX, 150, textLength, HEIGHT - 150); g2d.drawString(versionText, imageX, HEIGHT - bottomOffsetVersion); } g2d.setClip(0, 0, WIDTH, HEIGHT); g2d.setColor(Color.DARK_GRAY); g2d.drawRect(0, 0, WIDTH - 1, HEIGHT - 1); } public Dimension getPreferredSize() { return new Dimension(WIDTH, HEIGHT); } } // class AboutImagePanel }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -