java
1package MusicPlayer; 2 3import java.awt.BorderLayout; 4import java.awt.Color; 5import java.awt.EventQueue; 6import java.awt.Font; 7import java.awt.FontMetrics; 8import java.awt.GradientPaint; 9import java.awt.Graphics; 10import java.awt.Graphics2D; 11import java.awt.Point; 12import java.awt.Rectangle; 13import java.awt.SystemColor; 14import java.awt.event.ActionEvent; 15import java.awt.event.ActionListener; 16 17import javax.swing.JFileChooser; 18import javax.swing.JFrame; 19import javax.swing.JLabel; 20import javax.swing.JMenu; 21import javax.swing.JMenuBar; 22import javax.swing.JMenuItem; 23import javax.swing.SwingUtilities; 24import javax.swing.UIManager; 25import javax.swing.filechooser.FileNameExtensionFilter; 26 27public class GUI implements ActionListener { 28 29 private JFrame frmNovaMusicPlayer; 30 private JLabel lblNovaMusicPlayer; 31 private JMenuBar menuBar; 32 private JMenu menu; 33 private JMenuItem menuItem_1; 34 /** 35 * Launch the application. 36 */ 37 public static void main(String[] args) { 38 EventQueue.invokeLater(new Runnable() { 39 public void run() { 40 try { 41 GUI window = new GUI(); 42 window.frmNovaMusicPlayer.setVisible(true); 43 } catch (Exception e) { 44 e.printStackTrace(); 45 } 46 } 47 }); 48 } 49 50 /** 51 * Create the application. 52 */ 53 public GUI() { 54 initialize(); 55 } 56 57 /** 58 * Initialize the contents of the frame. 59 */ 60 private void initialize() { 61 frmNovaMusicPlayer = new JFrame(); 62 frmNovaMusicPlayer.setBackground(SystemColor.textHighlight); 63 frmNovaMusicPlayer.setTitle("Nova Music Player"); 64 frmNovaMusicPlayer.setBounds(100, 100, 854, 450); 65 frmNovaMusicPlayer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 66 frmNovaMusicPlayer.getContentPane().setLayout(new BorderLayout(0, 0)); 67 68 menuBar = new JMenuBar(); 69 menuBar.setBorderPainted(false); 70 menuBar.setBackground(new Color(255, 255, 255)); 71 menuBar.setFont(new Font("Yu Gothic UI", Font.PLAIN, 12)); 72 frmNovaMusicPlayer.getContentPane().add(menuBar, BorderLayout.NORTH); 73 74 try { 75 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 76 } catch (Exception e) { 77 e.printStackTrace(); 78 } 79 80 Font menuFont = new Font("Yu Gothic UI", Font.PLAIN, 12); 81 UIManager.put("Menu.font", menuFont); 82 UIManager.put("MenuItem.font", menuFont); 83 84 menu = new JMenu("ファイル"); 85 menuBar.add(menu); 86 87 menuItem_1 = new JMenuItem("音楽ファイルを開く"); 88 menu.add(menuItem_1); 89 menuItem_1.addActionListener(this); 90 menuItem_1.setActionCommand("Button 1"); 91 92 lblNovaMusicPlayer = new JLabel("Nova Music Player") 93 { 94 @Override 95 public void paintComponent(Graphics g) { 96 final Graphics2D g2 = (Graphics2D) g.create(); 97 g2.setFont(getFont()); 98 Rectangle viewR = new Rectangle(); 99 viewR.width = getSize().width; 100 viewR.height = getSize().height; 101 Rectangle iconR = new Rectangle(); 102 Rectangle textR = new Rectangle(); 103 SwingUtilities.layoutCompoundLabel(this, g2.getFontMetrics(), 104 getText(), getIcon(), 105 getVerticalAlignment(), getHorizontalAlignment(), 106 getVerticalTextPosition(), getHorizontalTextPosition(), 107 viewR, iconR, textR, getIconTextGap()); 108 109 FontMetrics fm = g2.getFontMetrics(); 110 111 g2.setPaint(new GradientPaint(new Point(textR.x, textR.y), Color.RED, 112 new Point(textR.x, textR.y + textR.height), Color.YELLOW.darker())); 113 114 g2.drawString(getText(), textR.x, textR.y + fm.getMaxAscent()); 115 g2.dispose(); 116 } 117 }; 118 lblNovaMusicPlayer.setToolTipText(""); 119 lblNovaMusicPlayer.setFont(new Font("源界明朝", Font.PLAIN, 80)); 120 frmNovaMusicPlayer.getContentPane().add(lblNovaMusicPlayer, BorderLayout.CENTER); 121 } 122 123 public void actionPerformed(ActionEvent e) { 124 String cmd = e.getActionCommand(); 125 if(cmd.equals("menuItem_1")){ 126 JFileChooser chooser = new JFileChooser(); 127 FileNameExtensionFilter extension = new FileNameExtensionFilter("音声ファイル","mp3","wav"); 128 chooser.setFileFilter(extension); 129 int result = chooser.showOpenDialog(this); 130 if(result == JFileChooser.APPROVE_OPTION) { 131 } 132 if(result == JFileChooser.CANCEL_OPTION) { 133 } 134 if(result == JFileChooser.ERROR_OPTION) { 135 } 136 137 } 138 } 139 140 141 } 142 143 144 145
回答1件
あなたの回答
tips
プレビュー