JAVA
1コードpackage gazou; 2 3import javax.swing.JFrame; 4import javax.swing.JPanel; 5 6public class MainFrame extends JFrame{ 7 8 public String[] PanelNames = {"mp","1","2","3","4","5","6","7","8","9"}; 9 Taitoru0 mp = new Taitoru0(this,PanelNames[0]); 10 Mode1 sp = new Mode1(this,PanelNames[1]); 11 Cara2 sp2 = new Cara2(this,PanelNames[2]); 12 Loading3 sp3 = new Loading3(this,PanelNames[3]); 13 Stage4 sp4 = new Stage4(this,PanelNames[4]); 14 VS5 sp5 = new VS5(this,PanelNames[5]); 15 Batoru6 sp6 = new Batoru6(this,PanelNames[6]); 16 Result7 sp7 = new Result7(this,PanelNames[7]); 17 // bunki8 sp8 = new bunki8(this,PanelNames[8]); 18 19 20 21 public MainFrame(){ 22 this.add(mp);mp.setVisible(true); 23 this.add(sp);sp.setVisible(false); 24 this.add(sp2);sp2.setVisible(false); 25 this.add(sp3);sp3.setVisible(false); 26 this.add(sp4);sp4.setVisible(false); 27 this.add(sp5);sp5.setVisible(false); 28 this.add(sp6);sp6.setVisible(false); 29 this.add(sp7);sp7.setVisible(false); 30 // this.add(sp8);sp8.setVisible(false); 31 // this.add(sp9);sp9.setVisible(false); 32 33 this.setBounds(100, 100, 800, 600); 34 } 35 public static void main(String[] args) { 36 MainFrame mf = new MainFrame(); 37 mf.setDefaultCloseOperation(EXIT_ON_CLOSE); 38 mf.setTitle("ACE DREAM MATCH");//タイトルバーの名前 39 mf.setVisible(true); 40 } 41 public void PanelChange(JPanel jp, String str){ 42 System.out.println(jp.getName()); 43 String name = jp.getName(); 44 if(name==PanelNames[0]){ 45 mp = (Taitoru0)jp; 46 mp.setVisible(false); 47 }else if(name==PanelNames[1]){ 48 sp = (Mode1)jp; 49 sp.setVisible(false); 50 }else if(name==PanelNames[2]){ 51 sp2 = (Cara2)jp; 52 sp2.setVisible(false); 53 }else if(name==PanelNames[3]){ 54 sp3 = (Loading3)jp; 55 sp3.setVisible(false); 56 }else if(name==PanelNames[4]){ 57 sp4 = (Stage4)jp; 58 sp4.setVisible(false); 59 }else if(name==PanelNames[5]){ 60 sp5 = (VS5)jp; 61 sp5.setVisible(false); 62 }else if(name==PanelNames[6]){ 63 sp6 = (Batoru6)jp; 64 sp6.setVisible(false); 65 }else if(name==PanelNames[7]){ 66 sp7 = (Result7)jp; 67 sp7.setVisible(false); 68 }//else if(name==PanelNames[8]){ 69 // sp8 = (bunki8)jp; 70 // sp8.setVisible(false); 71 // }//else if(name==PanelNames[9]){ 72 // sp9 = (Mode1_m9)jp; 73 // sp9.setVisible(false); 74 //} 75 if(str==PanelNames[0]){ 76 mp.setVisible(true); 77 }else if(str==PanelNames[1]){ 78 sp.setVisible(true); 79 }else if(str==PanelNames[2]){ 80 sp2.setVisible(true); 81 }else if(str==PanelNames[3]){ 82 sp3.setVisible(true); 83 }else if(str==PanelNames[4]){ 84 sp4.setVisible(true); 85 }else if(str==PanelNames[5]){ 86 sp5.setVisible(true); 87 }else if(str==PanelNames[6]){ 88 sp6.setVisible(true); 89 }else if(str==PanelNames[7]){ 90 sp7.setVisible(true); 91 }/*else if(str==PanelNames[8]){ 92 sp8.setVisible(true); 93 } 94 //else if(str==PanelNames[9]){ 95 // sp9.setVisible(true); 96 //}*/ 97 } 98 99 100}
Java
1コードpackage gazou; 2 3import java.awt.Color; 4import java.awt.event.ActionEvent; 5import java.awt.event.ActionListener; 6 7import javax.swing.JButton; 8import javax.swing.JLabel; 9import javax.swing.JPanel; 10 11 12 13public class Taitoru0 extends JPanel { 14 JButton btn,btn2,btn3; 15 JLabel paneltitle; 16 MainFrame mf; 17 String str; 18 19 public Taitoru0(MainFrame m,String s){ 20 mf = m; 21 str = s; 22 this.setName("mp"); 23 this.setLayout(null); 24 this.setSize(500, 400); 25 paneltitle = new JLabel("これは" 26 +getClass().getCanonicalName()+"タイトルクラスのパネルです"); 27 paneltitle.setBounds(0, 5, 400, 40); 28 this.add(paneltitle); 29 // 30 btn = new JButton("モード選択に移動"); 31 btn.setBounds(20, 50, 150, 40); 32 btn.addActionListener(new ActionListener(){ 33 public void actionPerformed(ActionEvent e){ 34 pc(); 35 } 36 }); 37 this.add(btn); 38 /* 39 btn2 = new JButton("SubPanel2に移動"); 40 btn2.setBounds(20, 100, 150, 40); 41 btn2.addActionListener(new ActionListener(){ 42 public void actionPerformed(ActionEvent e){ 43 pc(mf.PanelNames[2]); 44 } 45 }); 46 this.add(btn2); 47 btn3 = new JButton("SubPanel3に移動"); 48 btn3.setBounds(200, 100, 150, 40); 49 btn3.addActionListener(new ActionListener(){ 50 public void actionPerformed(ActionEvent e){ 51 pc(mf.PanelNames[3]); 52 } 53 }); 54 this.add(btn3);*/ 55 Float f = (float) Math.random(); 56 this.setBackground(Color.getHSBColor(f, 0.9f, 0.9f)); 57 58 } 59 public void pc(){ 60 mf.PanelChange((JPanel)this,mf.PanelNames[1]); 61 } 62} 63
java
1package gazou; 2 3import java.awt.event.ActionEvent; 4import java.awt.event.ActionListener; 5 6import javax.swing.JButton; 7import javax.swing.JPanel; 8 9 10public class Mode1 extends Cara2 { 11 JButton btn1,btn2; 12 public Mode1(MainFrame m,String s){ 13 super(m,s); 14 mf = m; 15 str = s; 16 btn1 = new JButton("シングルプレイ"); 17 btn1.setBounds(20, 50, 150, 40); 18 btn1.addActionListener(new ActionListener(){ 19 public void actionPerformed(ActionEvent e){ 20 pc(); 21 } 22 }); 23 this.add(btn1); 24 // 25 btn2 = new JButton("マルチプレイ"); 26 btn2.setBounds(20, 100, 150, 40); 27 btn2.addActionListener(new ActionListener(){ 28 public void actionPerformed(ActionEvent e){ 29 pc(); 30 } 31 }); 32 this.add(btn2); 33 } 34 35 36 37 @Override 38 public void pc(){ 39 mf.PanelChange((JPanel)this, mf.PanelNames[2]); 40 } 41} 42 43 44
```Java コードimport javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; public class Cara2 extends Loading3 { public Cara2(MainFrame m,String s){ super(m,s); JPanel p = new JPanel(); ImageIcon icon1 = new ImageIcon("Z:/Java/gazou1/bin/gazou1/ca-bi.png"); JButton button1 = new JButton(icon1); button1.setIcon(icon1); button1.setBounds(20, 50, 150, 40); button1.setText("カービィ "); p.add(button1); } @Override public void pc(){ mf.PanelChange((JPanel)this, mf.PanelNames[3]); } }
Java
1コードpackage gazou; 2 3import javax.swing.JButton; 4import javax.swing.JPanel; 5 6public class Loading3 extends Stage4 { 7 JButton btn1,btn2; 8 public Loading3(MainFrame m,String s){ 9 super(m,s); 10 btn.setText("0000000000"); 11 } 12 @Override 13 public void pc(){ 14 mf.PanelChange((JPanel)this, mf.PanelNames[4]); 15 } 16}
[引用サイト2](http://nowloading.blog.jp/archives/36741210.html)