Swing を使用して作成された2 つの異なるプログラムMenuWindow.java
とSettingsWindow.java
両方の GUI があります。SettingsWindow.java
のボタンをクリックして開くことはできますMenuWindow.java
か?
以下に 2 つのコードを示します。
MenuWindow.java
import java.awt.*;
import javax.swing.*;
public class MenuWindow
{
JFrame f ;
JMenuBar m ;
JMenu File , Settings , Timer , Programs , Store , Run , Help ;
JMenuItem m1 , m2 , m3 , m4 , m5 , m6 , m7 , m8 , m9 , m10 , m11 , m12 ;
JButton jb1, jb2, jb3 , jb4 , jb5 , jb6;
public MenuWindow()
{
f = new JFrame("Reflow") ;
f.setSize(600, 600) ;
m = new JMenuBar() ;
File = new JMenu("File") ;
Settings = new JMenu("Settings") ;
Timer = new JMenu("Timer") ;
Programs = new JMenu("Programs") ;
Store = new JMenu("Store");
Run = new JMenu("Run");
Help = new JMenu("Help");
m1 = new JMenuItem("Exit") ;
m2 = new JMenuItem("Temperature") ;
m3 = new JMenuItem("Clock") ;
m4 = new JMenuItem("Profile") ;
m5 = new JMenuItem(" Weekly Timer") ;
m6 = new JMenuItem("Preset Programs") ;
m7 = new JMenuItem("Errors") ;
m8 = new JMenuItem("Profile") ;
m9 = new JMenuItem("Auto Run") ;
m10 = new JMenuItem("Profile Run") ;
m11 = new JMenuItem("Manual Run") ;
m12 = new JMenuItem("About");
ImageIcon SettingsIc = new ImageIcon("settings.png");
jb1 = new JButton(SettingsIc);
jb1.setFocusPainted( false );
//jb1.setBorderPainted(false);
jb1.setContentAreaFilled(false);
ImageIcon TimerIc = new ImageIcon("clock.png");
jb2 = new JButton(TimerIc);
jb2.setFocusPainted( false );
//jb2.setBorderPainted(false);
jb2.setContentAreaFilled(false);
ImageIcon ProgramsIc = new ImageIcon("programs.png");
jb3 = new JButton(ProgramsIc);
jb3.setFocusPainted( false );
//jb3.setBorderPainted(false);
jb3.setContentAreaFilled(false);
ImageIcon StoreIc = new ImageIcon("store.png");
jb4 = new JButton(StoreIc);
jb4.setFocusPainted( false );
//jb4.setBorderPainted(false);
jb4.setContentAreaFilled(false);
ImageIcon RunIc = new ImageIcon("run.png");
jb5 = new JButton(RunIc);
jb5.setFocusPainted( false );
//jb5.setBorderPainted(false);
jb5.setContentAreaFilled(false);
ImageIcon ConnectIc = new ImageIcon("connect.png");
jb6 = new JButton(ConnectIc);
jb6.setFocusPainted( false );
//jb6.setBorderPainted(false);
jb6.setContentAreaFilled(false);
File.add(m1) ;
Settings.add(m2) ;
Settings.add(m3) ;
Settings.add(m4) ;
Timer.add(m5) ;
Programs.add(m6) ;
Store.add(m7);
Store.add(m8);
Run.add(m9);
Run.add(m10);
Run.add(m11);
Help.add(m12);
m.add(File) ;
m.add(Settings) ;
m.add(Timer) ;
m.add(Programs) ;
m.add(Store) ;
m.add(Run) ;
m.add(Help) ;
f.add(m) ;
f.add(jb1);
f.add(jb2);
f.add(jb3);
f.add(jb4);
f.add(jb5);
f.add(jb6);
jb1.setToolTipText("Settings");
jb2.setToolTipText("Weekly Timer");
jb3.setToolTipText("Program List");
jb4.setToolTipText("Store");
jb5.setToolTipText("Run");
jb6.setToolTipText("Connect");
System.out.println(System.getProperty("user.dir"));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setJMenuBar(m);
f.setLayout(new FlowLayout()) ;
f.setVisible(true) ;
}
public static void main(String[] arg)
{
MenuWindow w = new MenuWindow() ;
}
}
SettingsWindow.java
import java.awt.*;
import javax.swing.*;
public class SettingsWindow
{
JFrame f;
JButton b1, b2, b3;
public SettingsWindow()
{
f = new JFrame ("Settings") ;
f.setSize(400, 400) ;
ImageIcon TempuratureIc = new ImageIcon("heat.png");
b1 = new JButton(TempuratureIc);
b1.setFocusPainted(false);
//b1.setBorderPainted(false);
b1.setContentAreaFilled(false);
ImageIcon TimeIc = new ImageIcon("timetable.png");
b2 = new JButton(TimeIc);
b2.setFocusPainted(false);
//b2.setBorderPainted(false);
b2.setContentAreaFilled(false);
ImageIcon ProfileIc = new ImageIcon("graph.png");
b3 = new JButton(ProfileIc);
b3.setFocusPainted(false);
//b3.setBorderPainted(false);
b3.setContentAreaFilled(false);
f.add(b1);
f.add(b2);
f.add(b3);
b1.setToolTipText("Temperature Settings");
b2.setToolTipText("Time Settings");
b3.setToolTipText("Profile Settings");
System.out.println(System.getProperty("user.dir"));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
f.setVisible(true);
}
public static void main(String[] arg)
{
SettingsWindow w = new SettingsWindow() ;
}
}
誰か詳しく説明してくれませんか? 私はJavaが初めてです。