|
|
TopPage > Java関係 > Java関係[Sample Program] |
Program name |
Description License [execution script] |
Java version |
jar file Click File name, you can down load it. |
Source |
SayHello |
ボタンを押すたびに"Hello."と"!!!"の表示が変わります。 Frame作成の練習用なので、何かに使えるというものではありません。 License:javaのLicenseに準じます。 使用に関しては練習用ですので商用、営利目的の利用でないかぎり 自由にお使いください。 [java -jar SampelHello.jar &] |
JRE 8 (=version 1.8) | SayHello.jar | move to source page. |
package net.hobnote; import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; public class SayHello extends JFrame { private JPanel contentPane; JLabel lblHello = new JLabel("! ! !"); JButton btnSayHello = new JButton("Say Hello"); /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { SayHello frame = new SayHello(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public SayHello() { setResizable(false); setTitle("SayHello"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int F_WIDTH = 330; int F_HIGH = 280; setBounds(100, 100, F_WIDTH, F_HIGH); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JPanel panel = new JPanel(); panel.setBorder(new LineBorder(new Color(0, 0, 0))); panel.setBounds(6, 6, (F_WIDTH-20), 122); contentPane.add(panel); panel.setLayout(null); lblHello.setFont(new Font("Lucida Grande", Font.BOLD | Font.ITALIC, 16)); lblHello.setHorizontalAlignment(SwingConstants.CENTER); lblHello.setBounds(6, 26, (F_WIDTH-24), 66); panel.add(lblHello); btnSayHello.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String label_str; label_str = lblHello.getText(); if ( label_str.equals("! ! !") ) { lblHello.setText("Hello."); btnSayHello.setText("! ! !"); } else { lblHello.setText("! ! !"); btnSayHello.setText("Say Hello"); } } }); int SHbtn_WIDTH = 160; int SHbtn_X = (F_WIDTH-SHbtn_WIDTH)/2; btnSayHello.setBounds(SHbtn_X, 140, SHbtn_WIDTH, 50); contentPane.add(btnSayHello); JButton btnExit = new JButton("Exit"); btnExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); int EXTbtn_WIDTH = 120; int EXTbtn_X = F_WIDTH-EXTbtn_WIDTH-24; int EXTbtn_HIGH = 30; int EXTbtn_Y = F_HIGH-EXTbtn_HIGH-40; btnExit.setBounds(EXTbtn_X, EXTbtn_Y, EXTbtn_WIDTH, EXTbtn_HIGH); contentPane.add(btnExit); } } |
TopPage > Java関係 > Java関係[Sample Program] |