JFrameをフェードイン・フェードアウトさせてJPanelを入れ替えたい

このQ&Aのポイント
  • JFrameをフェードイン・フェードアウトさせながらJPanelを入れ替える方法について教えてください。
  • JFrameのフェードイン・フェードアウトを制御するためのMyFrameクラスの実装方法について教えてください。
  • フェード効果を実現するためにFadePaneクラスが使用されている点について詳しく教えてください。
回答を見る
  • ベストアンサー

JFrameをフェードイン・フェードアウトさせたい

JFrameを弄って、フェードしている間にJPanelを入れ替えたいと考えています。 newした時だけなぜかフェードイン後になります。 字数制限上省略しているので必要があれば補足などに追記します。 ****** public class MyFrame extends JFrame { public static final int NON_FADE = 0; public static final int IN_FADE = 1; public static final int FADE_OUTING = 2; public static final int FADE_INING = 3; private FadePane pane; private JPanel nowPanel; private Color fadeColor = Color.BLACK; private int fadeTime = 500; private int fadeStatus = NON_FADE; private boolean fadable = true; public MyFrame() { pane = new FadePane(); setGlassPane(pane); fadeOut(0, fadeColor); } public void fadeOut(int time, Color color) { setFadeColor(color); if (fadeStatus != NON_FADE) { return; } fadeStatus = FADE_OUTING; pane.fadeOut(time, color); fadeStatus = IN_FADE; } public void fadeIn(int time) { if (fadeStatus != IN_FADE) { return; } fadeStatus = FADE_INING; pane.fadeIn(time, getFadeColor()); fadeStatus = NON_FADE; repaint(); } public void setFadeColor(Color color) { if (color == null) { return; } if (fadeColor.equals(color)) { return; } fadeColor = color; this.getContentPane().setBackground(fadeColor); this.getContentPane().repaint(); } public void setPanel(JPanel panel) { if (fadable && !(nowPanel == null)) { fadeOut(fadeTime, fadeColor); } if(nowPanel!=null)this.getContentPane().remove(nowPanel); nowPanel = panel; if(nowPanel!=null)this.getContentPane().add(nowPanel); nowPanel.repaint(); if (fadable && !(nowPanel == null)) { fadeIn(fadeTime); } } private class FadePane extends JComponent { private JComponent com = this; private Color color = Color.BLACK; private final int renewalTime = 10; public void fadeOut(int time, Color color) { this.color = color; int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); int alpha = color.getAlpha(); FadeListener listener = new FadeListener(true, red, green, blue, alpha, time, renewalTime, this); Timer timer = new Timer(renewalTime, listener); listener.setTimer(timer); timer.start(); synchronized (this) { try { wait(); } catch (InterruptedException ex) { ex.printStackTrace(); } } } public void fadeIn(int time, Color color) { this.color = color; int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); int alpha = color.getAlpha(); FadeListener listener = new FadeListener(false, red, green, blue, alpha, time, renewalTime, this); Timer timer = new Timer(renewalTime, listener); listener.setTimer(timer); timer.start(); synchronized (this) { try { wait(); } catch (InterruptedException ex) { ex.printStackTrace(); } } } public synchronized void wakeup() { notifyAll(); } @Override protected void paintComponent(final Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(color); g2.fillRect(0, 0, this.getWidth(), this.getHeight()); } private class FadeListener implements ActionListener { //true:フェードアウト //false:フェードイン final boolean mode; final int red; final int green; final int blue; final int alpha; Timer timer; final int allTime; int time = 0; final int dTime; FadePane pane; public FadeListener(boolean mode, int red, int green, int blue, int alpha, int time, int dTime, FadePane pane) { this.mode = mode; this.red = red; this.green = green; this.blue = blue; this.alpha = alpha; this.allTime = (time / dTime) + 1; this.dTime = dTime; this.pane = pane; } public void setTimer(Timer timer) { this.timer = timer; } @Override public void actionPerformed(ActionEvent e) { if (time == 0) { com.setVisible(!mode); } time++; if (time > allTime) { com.setVisible(mode); timer.stop(); pane.wakeup(); return; } com.setVisible(true); int nowAlpha = mode ? alpha * time / allTime : alpha - (alpha * time / allTime); color = new Color(red, green, blue, nowAlpha); com.repaint(); } } } }

  • Java
  • 回答数2
  • ありがとう数2

質問者が選んだベストアンサー

  • ベストアンサー
  • _ranco_
  • ベストアンサー率58% (126/214)
回答No.2

これじゃだめなの? (私が文句言われる前にダウンロードして) http://homepage1.nifty.com/algafield/code.html なお、コードを投稿するときのマナーは: http://homepage1.nifty.com/algafield/sscce.html Javaのグラフィクスプログラミングの基礎は: http://homepage1.nifty.com/algafield/JavaGUIFaq19j.html 今度からは、問題だけにしぼった短いコード、構造がきれいで分かりやすく、コンパイルでき、実際に動くコードを投稿して欲しい。見る人は、そんなにひまじんではない。

foggi47
質問者

お礼

問題は完全に解決していました。ありがとうございます。 今度からはコードを整理して投稿させていただきます。お手数かけてすみませんでした。 困っていたので助かりました。

その他の回答 (1)

  • _ranco_
  • ベストアンサー率58% (126/214)
回答No.1

悲鳴:ちゃんとコンパイルできて、ちゃんと動いて、問題を再現できるコードを投稿してくれえーっ! (そのURLでもよい)。 それと、問題を説明する文も、もっと詳しくお願いします。 タイマーは、コントロールされるオブジェクトのクラス内ではなく、コントロールする側のクラス(トップレベルクラスのコンストラクタ内)で生成/スタートしてください。

foggi47
質問者

補足

文字数制限半角4000字がキツすぎる…っ 説明も削らざるを得ませんでした 問題は、新しいJPanelをセットした場合のみ発生するようです。 フェードアウト→セット→フェードインが 実際は フェードアウト→フェードイン→セットになります アップローダーなどに投稿してURLを張ると利用規約違反になるようで、以前消されたので…いい方法があれば教えてください コードを張るにあたってGameFrameと名づけていたのをMyFrameに直したのですが、他の場所も変えるのがめんどくさいのでGameFrameに直させていただきます まだ入りきっていません。セッター・ゲッターを省略しました sample1.pngがなくても動きます ****** import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class GameFrame extends JFrame { public static final int NON_FADE = 0; public static final int IN_FADE = 1; public static final int FADE_OUTING = 2; public static final int FADE_INING = 3; private FadePane pane; private JPanel nowPanel; private Color fadeColor = Color.BLACK; private int fadeTime = 500; private int fadeStatus = NON_FADE; private boolean fadable = true; private boolean keyBlock = true; private boolean mouseBlock = true; private KeyEventDispatcher keyDispatcher = new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent ke) { return keyBlock && !(fadeStatus == NON_FADE); } }; private MouseInputListener mouseListener = new MouseInputListener() { @Override public void mouseClicked(MouseEvent e) { if (keyBlock && !(fadeStatus == NON_FADE)) { e.consume(); } } @Override public void mousePressed(MouseEvent e) { if (keyBlock && !(fadeStatus == NON_FADE)) { e.consume(); } } @Override public void mouseReleased(MouseEvent e) { if (keyBlock && !(fadeStatus == NON_FADE)) { e.consume(); } } @Override public void mouseEntered(MouseEvent e) { if (keyBlock && !(fadeStatus == NON_FADE)) { e.consume(); } } @Override public void mouseExited(MouseEvent e) { if (keyBlock && !(fadeStatus == NON_FADE)) { e.consume(); } } @Override public void mouseDragged(MouseEvent e) { if (keyBlock && !(fadeStatus == NON_FADE)) { e.consume(); } } @Override public void mouseMoved(MouseEvent e) { if (keyBlock && !(fadeStatus == NON_FADE)) { e.consume(); } } }; public GameFrame() { pane = new FadePane(); setGlassPane(pane); fadeOut(0, fadeColor); KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher); pane.addMouseListener(this.mouseListener); pane.addMouseMotionListener(this.mouseListener); } ****** ここまでコンストラクタとフィールド ****** 前記のメソッドは省略 省略したメソッド public void fadeOut() { fadeOut(getFadeTime(), getFadeColor()); } public void fadeIn() { fadeIn(getFadeTime()); } ****** ここまでメソッド ****** 挙動を確認するクラス import java.awt.Color; import java.awt.Dimension; import javax.swing.*; public class NewMain { public static void main(String[] args) { final GameFrame frame = new GameFrame(); final JPanel panel1 = new JPanel(); JLabel label = new JLabel(); panel1.add(label); final JPanel panel2 = new JPanel(); JButton button = new JButton("button"); panel2.add(button); label.setIcon(new ImageIcon("sample1.png")); panel1.setBackground(Color.CYAN); panel2.setBackground(Color.MAGENTA); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200,150); frame.setFadeTime(1000); frame.setVisible(true); frame.setPanel(panel1);//うまく行く boolean frag = true; while(true){ synchronized(frame){ try { frame.wait(5000); } catch (InterruptedException ex) { ex.printStackTrace(); } } if(frag){ frame.setPanel(panel2);//一回目のみ失敗 frag=false; } else{ JPanel panel3 = new JPanel(); panel3.setBackground(Color.YELLOW); JTextField tf = new JTextField(); tf.setPreferredSize(new Dimension(100,20)); panel3.add(tf); frame.setPanel(panel3);//毎回失敗 frag = true; } synchronized(frame){ try { frame.wait(2000); } catch (InterruptedException ex) { ex.printStackTrace(); }}}}}

関連するQ&A

  • 画像をフェードインアウトさせたいのですが・・・

    勉強しながら四苦八苦しております。 今現在 背景を5つある画像の中からランダムに表示→数十秒ごとにその5つの画像からランダムに切り替え というものをなんとか完成させました。 それでこのランダムに切り替えるときに画像をフェードさせたいのですがどうも上手くいきません。。 // 画像を読み込む  num =Math.floor(Math.random() * 5); loadMovie(num + ".jpg", "img"); //何秒ごとに画像を切り替えるか setInterval(move,20000); //切り替える画像をランダムに表示 function move():Void { aaa =Math.floor(Math.random() * 4); loadMovie(aaa + ".jpg", "img"); } //以下を加えるとエラーになってしまいます。 onClipEvent(load) { flg = -1; myspd = 5; } onClipEvent(enterFrame) { tmp = this._alpha+(myspd*flg); if (tmp>100 { tmp = 100; flg = -1; } else if (tmp<0) { tmp = 0; flg = 1; } this._alpha = tmp; } どなたか分かるようでございましたらご教示下さい。。。 ヒントだけでもけっこうですので。

    • ベストアンサー
    • Flash
  • setIcon() の反対のようなものを探しています。

    こんばんは。GUIで、一秒ごとに画像を切り替える、スライドショーのようなものを作ってみたのですが、画像が切り替わらず、画像の上に画像が配置され、どんどん積み重なっていく感じになりました。以下がそのコードです。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class IconChange extends JFrame{ private Timer timer; private JLabel img; private int sec; private Icon[] icon=new ImageIcon[11]; private JPanel pane; public static void main(String[] args){ IconChange frame=new IconChange("画像チェンジ"); frame.pack(); frame.setDefaultCloseOperation(3); frame.setVisible(true); } public IconChange(String title){ super(title); sec = 0; pane=(JPanel)getContentPane(); pane.setPreferredSize(new Dimension(800,600)); pane.setOpaque(true); pane.setBackground(new Color(0x00000000, true)); img=new JLabel(new ImageIcon("images2/1.jpg")); pane.add(img); for(int i=0;i<=10;i++){ icon[i]=new ImageIcon("images2/"+i+".png"); } timer = new Timer(1000 , new Kirikae()); timer.start(); } class Kirikae implements ActionListener{ public void actionPerformed(ActionEvent e){ img.setIcon(icon[sec]); if(sec>=10){sec=0;} sec++; } } } JLabelに画像をセットしたら、前の画像と入れ替わり新しい画像がセットされるとおもったのですが、前の画像が残ったまま新しい画像がセットされます。新しい画像をセットする前に前の画像のセットを取り消したいのですが、いい方法がございましたらアドバイスお願いいたします。

    • ベストアンサー
    • Java
  • ボールが勝手に動き困ってます。

    前回にひき続き困ってます>< タイトル画面→(Enterクリック)→ゲーム画面までできたんですが ゲーム画面でボールとタイマーを動かしたくてやってみるとタイマーはうまく いったのにボールが動く速度を変更できず、勝手に動いてしまいます><どう 改善すればいいでしょうか。ソースコードみにくいですが助言お願いします。 import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.Timer; public class JavaGame3 { public static void main(String age[]) { JFrame frame = new JFrame(); frame.setTitle("ゲームフレーム"); frame.setSize(500, 550); frame.setLocation(1000, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Testpanel panel = new Testpanel(); frame.add(panel); frame.setVisible(true); } } class Testpanel extends JPanel implements Runnable{ private Ball[] balls; static final int TITLE = 0; static final int GAME = 1; private int mode; private int sec; private Timer timer; private Thread t; public Testpanel() { balls = new Ball[5]; java.util.Random rr = new java.util.Random(); for(int i=0; i<balls.length; i++) balls[i] = new Ball(10*i+6,10*i+31,rr.nextInt(5)+1, rr.nextInt(5)+1); sec = 0; setBackground(Color.black); addKeyListener(new JavaKeyListener()); setFocusable(true); timer = new Timer(1000, new JavaActionListener()); mode = TITLE; t = new Thread(this); } class JavaActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (sec == 30) { timer.stop(); } else { sec++; } } } private void drawTitle(Graphics g) { g.setColor(Color.blue); g.drawString("タイトル", 165, 150); g.setColor(Color.white); g.drawString("Hit Enter Key!", 150, 350); } public void drawGameOver(Graphics g) { g.setColor(Color.white); g.setColor(Color.red); g.drawString(sec + "sec", 230, 300); repaint(); for (int i=0; i<balls.length; i++) balls[i].draw(g); } protected void paintComponent(Graphics g) { super.paintComponent(g); if(mode == TITLE) { drawTitle(g); } else if(mode == GAME) { drawGameOver(g); } } class JavaKeyListener implements KeyListener { public void keyPressed(KeyEvent e){ int key = e.getKeyCode(); if(mode == TITLE) { switch(key) { case KeyEvent.VK_ENTER: mode = GAME; timer.start(); t.start(); sec = 0; break;} } else { switch (key) { case KeyEvent.VK_ENTER: mode = TITLE; break; } }repaint(); } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} } public void run() { while(true) { try { Thread.sleep(100); } catch (Exception e) {} repaint(); } } } class Ball { private int x, y, vx, vy, r; public Ball(int x, int y, int vx, int vy) { this.x = x; this.y = y; this.vx = vx; this.vy = vy; r = 30; } public void draw(Graphics g) { g.fillOval(x, y, r, r); x += vx; y += vy; if(x < 0 || x > 457) vx = -vx; if(y < 0 || y > 433) vy = -vy; } }

    • ベストアンサー
    • Java
  • JOptionPaneのダイアログパネルの背景色の変え方

    Javaのダイアログの背景色の変え方を教えてください。 今、課題を作成中なのですが、ダイアログパネルを出すとパネルの背景色が「ライトグレー」になります。その色が他のパネルの色と合わないので、変更したいと思い、setBackgroudなどで設定変更したのですが、色の変化がありません。SUNのAPIを見ると変更できそうなのですが、できませんでした。 変更の仕方をご存知でしたら、教えてください。 ソース1 private void Dialog_process(String msg) { JOptionPane pane = new JOptionPane(); JOptionPane.showMessageDialog(this,msg,"",JOptionPane.WARNING); pane.setForegroung(Color.red); pane.setBackground(Color.white); } ソース1の結果は ダイアログのパネル背景色は「ライトグレー」、文字色は「黒」です。 ソース2 private void Dialog_process(String msg) { JOptionPane pane = new JOptionPane(msg,JOptionPane.WARNING_MESSAGE); JDialog pane_dialog = pane.createDialog(this,""); pane.setForegroung(Color.red); pane.setBackground(Color.white); pane_dialog.show(); } ソース2の結果は ダイアログのパネル背景色の外は「白」、中は「ライトグレー」、文字色は「黒」です。 望む結果はパネル背景色が「白」、文字色は「赤」です。 制限事項はありません。もともと「JOptionPaneではパネル背景色が変えられないのでは」の疑問もあります。 お願いします。(^^

    • ベストアンサー
    • Java
  • javaの同期について

    javaの同期について package rwlock; public class App1 extends Thread { static private final int REFER = 0; static private final int UPDATE = 1; static private final int[] conf1 = { REFER, REFER, REFER, UPDATE }; static private final int[] conf2 = { REFER, UPDATE, REFER, REFER }; static private MyObj0 mo = new MyObj0(); // App1 + MyObj0 int id; private int[] conf; public App1(int id, int[] conf) { this.id = id; this.conf = conf; } public void run() { long tStart = Time.current(); for (int i = 0; i < conf.length; i++) { switch(conf[i]) { case REFER: mo.refer(); break; case UPDATE: mo.update(); break; default: assert false : "internal error"; } } if (id == 1) { Time.printElapsed(tStart); } } public static void main(String[] args) { App1 th1 = new App1(1, conf1); App1 th2 = new App1(2, conf2); th1.start(); th2.start(); } } public class MyObj0 { private Object countLock = new Object(); private int count; private void enter() { synchronized(countLock) { count++; } } private void leave() { synchronized(countLock) { count--; } } public MyObj0() { count = 0; } public void refer() { enter(); Time.sleep(300); leave(); } public void update() { enter(); synchronized(countLock) { assert count == 1; } Time.sleep(500); leave(); } において、updateの実行中は、他のスレッドでもupdateもreferも実行されないが、二つのスレッドで同時にreferは実行されうるという条件を満たすにはどうしたらよいでしょうか?updateにsynchronizedをつけてみましたが、referが同時に実行されてしまいました

    • ベストアンサー
    • Java
  • javaの同期について

    javaの同期について package rwlock; public class App1 extends Thread { static private final int REFER = 0; static private final int UPDATE = 1; static private final int[] conf1 = { REFER, REFER, REFER, UPDATE }; static private final int[] conf2 = { REFER, UPDATE, REFER, REFER }; static private MyObj0 mo = new MyObj0(); // App1 + MyObj0 int id; private int[] conf; public App1(int id, int[] conf) { this.id = id; this.conf = conf; } public void run() { long tStart = Time.current(); for (int i = 0; i < conf.length; i++) { switch(conf[i]) { case REFER: mo.refer(); break; case UPDATE: mo.update(); break; default: assert false : "internal error"; } } if (id == 1) { Time.printElapsed(tStart); } } public static void main(String[] args) { App1 th1 = new App1(1, conf1); App1 th2 = new App1(2, conf2); th1.start(); th2.start(); } } public class MyObj0 { private Object countLock = new Object(); private int count; private void enter() { synchronized(countLock) { count++; } } private void leave() { synchronized(countLock) { count--; } } public MyObj0() { count = 0; } public void refer() { enter(); Time.sleep(300); leave(); } public void update() { enter(); synchronized(countLock) { assert count == 1; } Time.sleep(500); leave(); } において、updateの実行中は、他のスレッドでもupdateもreferも実行されないが、二つのスレッドで同時にreferは実行されうるという条件を満たすにはどうしたらよいでしょうか?updateにsynchronizedをつけてみましたが、referが同時に実行されてしまいました。

    • ベストアンサー
    • Java
  • .Net Compact でのダブルバッファリング

    .Net Comapct Frameworkを利用してのC#プログラミングで、 ダブルバッファリングを利用して画面を描画しようとしていますが、 ちらつきが解消されません。 どこがおかしいかご指摘いただけると幸いです。 【環境】 Visual Studio 2005 C# .Net Compact Framework 2.0 【コード(抜粋)】 public partial class Form1 : Form { private Bitmap m_offScr; // オフスクリーンイメージ private Graphics m_offG; // オフスクリーングラフィックス private System.Windows.Forms.Timer timer1; public Form1() { this.timer1.Enabled = true; this.timer1.Interval = 1000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); ~略~ this.m_offScr = new Bitmap(400, 200); this.m_offG = Graphics.FromImage(this.m_offScr); } private void Form1_Paint(object sender, PaintEventArgs e) { m_offG.FillRectangle(new SolidBrush(Color.Red), 10, 10, 100, 100); e.Graphics.DrawImage(this.m_offScr, 0, 0); } // イベントハンドラ private void timer1_Tick(object sender, EventArgs e) { // 秒の更新 this.Refresh(); } } よろしくお願いいたします。

  • フェードアウト時にぶちっと画像が一瞬切れます。

    以下のように、アプリ起動時に、フェードインで現れてフェードアウトで消えていくフォームがあります その後に実際に使用するフォームを表示したいと思っています。 ただwindows8だと問題ないのですがXPやwindows7で下記コードを実行するとちょうど Thread.Sleep(4000)という命令以降フェードアウトしていくのですが この時一瞬画像がブチっとコマ落ちしたような現象がおきるのです。 原因がわからず困っております。 どなたか原因がわかるかたいらっしゃいませんでしょうか? お願いします! public class MainClass{ public static void Main(string [] args){ try{ FrontForm frontObj = new FrontForm(); frontObj.StartPosition = FormStartPosition.CenterScreen; frontObj.SetImage("f04.jpg"); frontObj.FormBorderStyle = FormBorderStyle.None; Application .EnableVisualStyles(); Application.Run(frontObj); Application.Run(new Form()); }catch(Exception e){ MessageBox.Show(e.ToString()); } } } public class FrontForm : Form{ //フェードさせるためのタイマーオブジェクト public System.Windows.Forms.Timer TimerObj ; //画面にフェードインアウトで表示させる画像用ラベル public Label labelObj ; //実際に表示させるための画像パス public string imagePath; //フェードインとアウトの境目フラグ public int fadeFlag; //コンストラクタ public FrontForm(){ this.Width = 900; this.Height = 400; this.labelObj = new Label(); this.labelObj.Width = this.ClientSize.Width; this.labelObj.Height = this.ClientSize.Height; this.Controls.Add(this.labelObj); this.Opacity = 0.0F; this.Visible = false; this.fadeFlag = 0; this.Load += new EventHandler(this.RenderFade); } //フェード用画像をセットする public void SetImage (string path){ Bitmap bit = new Bitmap(this.ClientSize.Width,this.ClientSize.Height); Graphics gr = Graphics.FromImage(bit); this.imagePath = path; Image imageObj = Image.FromFile(this.imagePath); gr.DrawImage(imageObj,0,0,this.ClientSize.Width,this.ClientSize.Height); this.labelObj.BackgroundImage =bit; } public void RenderFade(Object sender ,EventArgs e){ //タイマーイベントの作成 this.TimerObj = new System.Windows.Forms.Timer(); this.TimerObj.Tick += new EventHandler(this.RenderMethod); this.TimerObj.Interval = 30; this.TimerObj.Start(); } public void RenderMethod(Object sender ,EventArgs e){ if(this.fadeFlag == 0){ Console.WriteLine(this.Opacity.ToString()); this.Opacity += 0.01F; if(this.Opacity == 1){ this.fadeFlag = 1; Thread.Sleep(4000); } } if(this.fadeFlag == 1){ Console.WriteLine("====" + this.Opacity.ToString() + "===="); this.Opacity = this.Opacity - 0.01F; if(this.Opacity ==0){ this.Close(); } } } }

  • jFrameを使って複数の画面を生成するにはどうすれば良いのでしょうか?

    eclipseのVE機能を使ってjFrameの画面生成を勉強しているのですが、 複数の画面を生成することができません。。 以下のソースで、ボタンが押された時に新しく画面を生成するように しているのですが、なぜか生成できません。エラーもありません。 何が足りなかったのか、悪かったのかを指摘していただけますでしょうか? import javax.swing.JPanel; import javax.swing.JFrame; import java.awt.GridBagLayout; import javax.swing.JButton; import java.awt.GridBagConstraints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class jFrameTest extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JButton jButton = null; /** * This is the default constructor */ public jFrameTest() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(300, 200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; jContentPane = new JPanel(); jContentPane.setLayout(new GridBagLayout()); jContentPane.add(getJButton(), gridBagConstraints); } return jContentPane; } /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getJButton() { if (jButton == null) { jButton = new JButton(); jButton.setText("jButton"); jButton.addActionListener(this); } return jButton; } //ボタン入力リスナー public void actionPerformed(ActionEvent event) { String cmd = event.getActionCommand(); if(cmd == "jButton"){ jFrameTest jtest = new jFrameTest(); System.out.println("new"); } } }

    • ベストアンサー
    • Java
  • 文字をフェードインするHTML教えて下さい

    infoseekで勉強しながら会社のHP作ってますが、 文字をフェードインする方法が上手くいきません。 <script language="JavaScript"> <!-- count=0; Num=1; Time=100; function FadeIn(str){ c=str.charAt(count++); for(i=0;i<Num;i++){ document.all["Fade"+i].style.color="#"+c+c+c+c+c+c; } if(count<str.length){ setTimeout("FadeIn('"+str+"')",100); } } //--> </script> 次に、<body>タグ内を<BODY onload="FadeIn('fedcba9876543210')" >と変更すると、JAVAスクリプトの準備は終了になります。 後は、フェードインさせたい文字を、<span id="Fade0">文字列</span>と設定します。これで、文字がじんわりとフェードインして現れます。 上記はサンプルのコピーで、固定のバナーの下にHPへようこそ!という文字がフェードインします。 なのですが、どの部分がバナーのHTMLか、文字のHTMLか分からなく、 >>、<span id="Fade0">文字列</span> この意味もわかりません。表示したい文字を「文字列」に置き換えれば良いのですか??そしてこの一文をどこに組み込めば良いのかもわかりません・・・。 何度かやってみましたがエラーになってしまいます。 他の方法でも良いので、お解かりになるかた宜しくお願いいたします!

専門家に質問してみよう