現在javaを用いて、音楽ゲームを作成しています。
その中で、以下のような動作をする2つのjavaファイルを用意しています。
top.java
プログラム起動後のトップ画面の表示‐>曲選択画面の表示
play.java
音楽再生、譜面描画、判定など音楽ゲームを動かす。
そこで、top.javaからplay.java に飛ばして、音楽ゲームの動作をするプログラムと、それ以外の処理を行うプログラムで分けて動作させたいと思い
play.javaをインスタンス化してtop.javaから呼び出したのですが、
play.java内の音楽再生、譜面読み込み等の他の処理は動いているのですが、画面描画だけ上手く動かず、ただ白い画面(デフォルトの薄いグレーではない)が表示されるのみです。
別プログラムのGUIを表示させるとき、何か特別な処理等が必要なのでしょうか。
java
1top.java 2 3import 省略 4 5public class top extends JFrame implements ActionListener{ 6 7 8 static top frame = new top("* 。violin mania。 *"); 9 static JFrame frames = new JFrame("* 。 music select。 *");//曲選択 10 public static int[] sec = new int[1000]; 11 public static int[][] fumen = new int[1000][2]; 12 static play startgame = new play(); 13 14 15 16 public static void main(String args[]){ 17 frame.setVisible(true); 18 } 19 20 top(String title){ 21 setTitle(title); 22 setBounds(600,10,600,1000); 23 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 24 25 JPanel p = new JPanel(); 26 p.setLayout(null); 27 p.setOpaque(true); 28 29 30 ImageIcon top_bg = new ImageIcon("top.png"); 31 JLabel bg1 = new JLabel(top_bg); 32 bg1.setBounds(0,0,600,1000); 33 34 ImageIcon icon2 = new ImageIcon("option.png"); 35 JButton fileButton = new JButton(icon2); 36 fileButton.setBounds(370,750,200,50); 37 fileButton.addActionListener(this); 38 39 ImageIcon icon1 = new ImageIcon("start.png"); 40 JButton button = new JButton(icon1); 41 button.setBounds(370,600,200,50); 42 button.addActionListener(this); 43 button.setActionCommand("start"); 44 45 p.add(bg1); 46 p.add(button); 47 p.add(fileButton); 48 49 50 51 Container contentPane = getContentPane(); 52 contentPane.add(p, BorderLayout.CENTER); 53 54 } 55 public void actionPerformed(ActionEvent e){ 56 String cmd = e.getActionCommand(); 57 AudioClip audio = null; 58 if (cmd.equals("start")){ 59 frame.setVisible(false); 60 frames.setBounds(600,10,600,1000); 61 frames.getContentPane().setBackground(Color.black); 62 frames.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 63 JPanel p_select = new JPanel(); 64 p_select.setLayout(null); 65 p_select.setOpaque(false); 66 67 ImageIcon concon1 = new ImageIcon("./music/concon/concon_out.png"); 68 ImageIcon concon2 = new ImageIcon("./music/concon/concon_over.png"); 69 JButton music3 = new JButton(concon1); 70 music3.setBounds(100,500,410,116); 71 music3.setRolloverIcon(concon2); 72 music3.setPressedIcon(concon2); 73 music3.addActionListener(this); 74 music3.setActionCommand("./music/concon/concon"); 75 76 p_select.add(music3); 77 78 79 Container contentPane2 = frames.getContentPane(); 80 contentPane2.add(p_select, BorderLayout.CENTER); 81 82 frames.setVisible(true); 83 84 }else if (cmd.equals("./music/concon/concon")){ 85 frames.setVisible(false); 86 startgame.game();//ここでplay.javaを呼び出す。 87 88 89 audio.stop(); 90 } 91 } 92 93 94}
java
1import 省略 2 3public class play { 4 5 public static void game(){ 6 vimani action = new vimani(); 7 action.viner(); 8 } 9} 10 11class vimani extends JPanel implements KeyListener{ 12 13 private JFrame frameC; 14 public lanePanel violin; 15 public static int[] sec = new int[1000]; 16 public static int[][] fumen = new int[1000][2]; 17 public static long gets = 0; 18 static int muchmicros = 0; 19 static int y1ic=0;static int y2ic=0;static int y3ic=0;static int y4ic=0; 20 static int[] y1 = new int[300]; 21 static int[] y2 = new int[300]; 22 static int[] y3 = new int[300]; 23 static int[] y4 = new int[300]; 24 static int speed = 7; 25 static String filen = "concon"; 26 static int startcounter=0; 27 static Sounder sounder = new Sounder(); 28 public void viner(){ 29 window();//ウィンドウを生成 30 for(int i=0;i<300;i++){ 31 y1[i] = 0; 32 y2[i] = 0; 33 y3[i] = 0; 34 y4[i] = 0; 35 } 36 read_fumen(filen); 37 runi(); 38 } 39 40 public void window(){ 41 42 frameC = new JFrame(); 43 frameC.setTitle("Violinist"); 44 frameC.setBounds(600,10,600,1000);//x=600,y=10,横600,縦1000のフレームを準備 45 frameC.setLayout(null);//レイアウトマネージャ使用しない 46 frameC.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//一緒に消す 47 48 violin = new lanePanel(); 49 violin.setOpaque(false); 50 violin.setLayout(null); 51 52 violin.setSize(600,1000); 53 violin.setBackground(new Color(31,38,56,255)); 54 55 Container contentPane3 = frameC.getContentPane(); 56 contentPane3.add(violin, BorderLayout.CENTER); 57 58 59 //frame.add(violin); 60 61 frameC.setVisible(true); 62 63 frameC.addKeyListener(this); 64 violin.addKeyListener(this); 65 66 } 67 68 public void runi(){//指定msでrepaint()を行うメソッド 69 violin.repaint();//repaintを呼び出す。 70 } 71 72public static void fumeneed(){ 73 //譜面データを読む処理 74} 75 76public static void musicstart(String selectMusic){ 77 //音楽再生処理 78} 79 80 public static void read_fumen(String fileName){ 81 //譜面ファイルをオープンする処理 82} 83 84 private static boolean checkBeforeReadfile(File file){ 85 //譜面ファイルを読むのに必要な処理 86 } 87 88 public void keyPressed(KeyEvent e){ 89 } 90 public void keyReleased(KeyEvent e){ 91 } 92 public void keyTyped(KeyEvent e){ 93 char key = e.getKeyChar(); 94 System.out.println(key); 95 searchHitNotes(key);//キー判定 96 } 97public void searchHitNotes(char hitKey){ 98 //キーの押したタイミングで点数をつける処理 99} 100} 101 102class Sounder implements LineListener{ 103 //音楽再生準備、再生中かどうかの判定等をするクラス 104} 105 class lanePanel extends JPanel{//譜面描画メソッド 106 107 @Override 108 public void paintComponent(Graphics g) { 109 super.paintComponent(g); 110 111 // レーン 112 g.setColor(new Color(153,51,51,255)); 113 g.fillRect(220,10, 30, 650); 114 g.fillRect(255,10, 30, 650); 115 g.fillRect(290,10, 30, 650); 116 g.fillRect(325,10, 30, 650); 117 118 g.setColor(new Color(255,255,255,255)); 119 g.fillRect(250,10, 5, 650); 120 g.fillRect(285,10, 5, 650); 121 g.fillRect(320,10, 5, 650); 122 123 g.setColor(new Color(255,180,0,255)); 124 g.fillRect(220,590,135,20); 125 //ノート 126 g.setColor(new Color(102,255,204,255));//ノーツの色 127 for(int i=vimani.one+1;i<vimani.y1ic;i++){ 128 if(vimani.y1[i] <640){ 129 g.fillRoundRect(220, vimani.y1[i], 30, 20, 5, 10); 130 vimani.y1[i]+=vimani.speed; 131 }else{ 132 vimani.y1[i] = 990; 133 vimani.one = i; 134 } 135 } 136 for(int i=vimani.two+1;i<vimani.y2ic;i++){ 137 if(vimani.y2[i] <640){ 138 g.fillRoundRect(255, vimani.y2[i], 30, 20, 5, 10); 139 vimani.y2[i]+=vimani.speed; 140 }else{ 141 vimani.y2[i] = 990; 142 vimani.two = i; 143 } 144 } 145 for(int i=vimani.three+1;i<vimani.y3ic;i++){ 146 if(vimani.y3[i] <640){ 147 g.fillRoundRect(290, vimani.y3[i], 30, 20, 5, 10); 148 vimani.y3[i]+=vimani.speed; 149 }else{ 150 vimani.y3[i] = 990; 151 vimani.three = i; 152 } 153 } 154 for(int i=vimani.four+1;i<vimani.y4ic;i++){ 155 if(vimani.y4[i] <640){ 156 g.fillRoundRect(325, vimani.y4[i], 30, 20, 5, 10); 157 vimani.y4[i]+=vimani.speed; 158 }else{ 159 vimani.y4[i] = 990; 160 vimani.four=i; 161 } 162 } 163 164 } 165 166 public void addObj(){ 167 } 168 } 169

回答1件
あなたの回答
tips
プレビュー