Java アプリを Win32 アプリのように見せかける JSmooth を試す
package com.snail; import java.awt.Rectangle; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class PRS extends JFrame { private static final long serialVersionUID = 1L; private ImageIcon iconPaper = null; private ImageIcon iconRock = null; private ImageIcon iconScissors = null; private JButton jComButton = null; private JButton jPaperButton = null; private JButton jRockButton = null; private JButton jScissorsButton = null; private JLabel jVsLabel = null; private JPanel jContentPane = null; private Thread currentThread = null; // @jve:decl-index=0: private ImageIcon[] icons = null; private int currentHand = 0; public PRS() { super(); initialize(); } public static void main(final String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { PRS thisClass = new PRS(); thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisClass.setVisible(true); } }); } private void showDialog(final String title, final String message, final int type) { JOptionPane.showMessageDialog(this, message, title, type); } private ImageIcon getIconPaper() { if (iconPaper == null) { iconPaper = new ImageIcon(getClass().getResource("/com/snail/paper.gif")); } return iconPaper; } private ImageIcon getIconRock() { if (iconRock == null) { iconRock = new ImageIcon(getClass().getResource("/com/snail/rock.gif")); } return iconRock; } private ImageIcon getIconScissors() { if (iconScissors == null) { iconScissors = new ImageIcon(getClass().getResource( "/com/snail/scissors.gif")); } return iconScissors; } private ImageIcon[] getIcons() { if (icons == null) { icons = new ImageIcon[] { getIconPaper(), getIconRock(), getIconScissors() }; } return icons; } private JButton getJComButton() { if (jComButton == null) { jComButton = new JButton(); jComButton.setBounds(new Rectangle(11, 12, 59, 49)); jComButton.setIcon(getIconPaper()); } return jComButton; } private JPanel getJContentPane() { if (jContentPane == null) { jVsLabel = new JLabel(); jVsLabel.setBounds(new Rectangle(77, 45, 16, 16)); jVsLabel.setText("VS"); jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(getJComButton(), null); jContentPane.add(getJPaperButton(), null); jContentPane.add(getJRockButton(), null); jContentPane.add(getJScissorsButton(), null); jContentPane.add(jVsLabel, null); } return jContentPane; } private void showWinDialog() { showDialog("Win", "You Win", JOptionPane.INFORMATION_MESSAGE); } private void showDrawDialog() { showDialog("Draw", "Draw Game", JOptionPane.WARNING_MESSAGE); } private void showLoseDialog() { showDialog("Lose", "You Lose", JOptionPane.ERROR_MESSAGE); } private JButton getJPaperButton() { if (jPaperButton == null) { jPaperButton = new JButton(); jPaperButton.setBounds(new Rectangle(101, 12, 59, 49)); jPaperButton.setIcon(getIconPaper()); jPaperButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent e) { currentThread.interrupt(); try { currentThread.join(); switch (currentHand) { case 0: showDrawDialog(); break; case 1: showWinDialog(); break; default: showLoseDialog(); break; } } catch (InterruptedException e1) { e1.printStackTrace(); } currentThread = new Roller(); currentThread.start(); } }); } return jPaperButton; } private JButton getJRockButton() { if (jRockButton == null) { jRockButton = new JButton(); jRockButton.setBounds(new Rectangle(171, 12, 59, 49)); jRockButton.setIcon(getIconRock()); jRockButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent e) { currentThread.interrupt(); try { currentThread.join(); switch (currentHand) { case 0: showLoseDialog(); break; case 1: showDrawDialog(); break; default: showWinDialog(); break; } } catch (InterruptedException e1) { e1.printStackTrace(); } currentThread = new Roller(); currentThread.start(); } }); } return jRockButton; } private JButton getJScissorsButton() { if (jScissorsButton == null) { jScissorsButton = new JButton(); jScissorsButton.setBounds(new Rectangle(241, 12, 59, 49)); jScissorsButton.setIcon(getIconScissors()); jScissorsButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent e) { currentThread.interrupt(); try { currentThread.join(); switch (currentHand) { case 0: showWinDialog(); break; case 1: showLoseDialog(); break; default: showDrawDialog(); break; } } catch (InterruptedException e1) { e1.printStackTrace(); } currentThread = new Roller(); currentThread.start(); } }); } return jScissorsButton; } private void initialize() { this.setSize(316, 98); this.setContentPane(getJContentPane()); this.setTitle("Paper-Rock-Scissors"); ImageIcon icon = new ImageIcon( ClassLoader.getSystemResource("com/snail/rock.gif") ); this.setIconImage(icon.getImage()); currentThread = new Roller(); currentThread.start(); } class Roller extends Thread { public void run() { while (true) { try { Thread.sleep(100L); } catch (InterruptedException e) { getJComButton().setIcon(getIcons()[currentHand]); break; } getJComButton().setIcon(getIcons()[currentHand]); currentHand = (currentHand + 1) % 3; } } } }