• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:コミュニケーション支援用の画面を作っております)

コミュニケーション支援用の画面を作る方法

_ranco_の回答

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

> タブパネルに、コンポーネントを配置したいのですが それは、tabPanel1.add(nantoka);などですよ。 tabPanel1や2に、レイアウトマネージャを設定するといいですね。

関連するQ&A

  • JAVAでの背景画像表示

    現在javaでゲームのメニュー画面を作っているのですが、ボタンを配置する所まではできたんですが、背景に画像を表示することができなくて困っています! import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.ImageIcon; import java.awt.Container; import java.awt.BorderLayout; import javax.swing.border.LineBorder; import javax.swing.border.EtchedBorder; import java.awt.Color; import java.awt.Container; public class Mati extends JFrame{ public static void main(String[] args){ Mati frame = new Mati(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(10, 10,650,650); frame.setTitle("街"); frame.setVisible(true); JPanel h = new JPanel(); h.setOpaque(false); ImageIcon icon1 = new ImageIcon("Mati.jpg"); JLabel label1 = new JLabel(icon1); JLabel label2 = new JLabel(); h.add(label1); } Mati(){ JButton button1 = new JButton("宿屋"); button1.setFont(new Font("Mairyo", Font.PLAIN, 30)); JButton button2 = new JButton("道具屋"); button2.setFont(new Font("Mairyo", Font.PLAIN, 30)); JButton button3 = new JButton("武器屋"); button3.setFont(new Font("Mairyo", Font.PLAIN, 30)); JButton button4 = new JButton("街を出る"); button4.setFont(new Font("Mairyo", Font.PLAIN, 30)); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(Box.createRigidArea(new Dimension(10,30))); p.add(button1); p.add(Box.createRigidArea(new Dimension(5,8))); p.add(button2); p.add(Box.createRigidArea(new Dimension(5,8))); p.add(button3); p.add(Box.createRigidArea(new Dimension(5,8))); p.add(button4); getContentPane().add(p, BorderLayout.CENTER); } } ソースはこのようになっています。これからどうすれば背景画像が表示されるか教えていただきたいです。 よろしくお願いします。

  • tabにdrawImageで画像を描画したい

    tabにdrawImageで画像を描画したい 以下のソースでtabbedpaneに対して、ImageIconを指定して画像をのせるではなく、 drawImageメソッドで描画したいです。 ご存知の方がおられましたら教えてください。 import javax.swing.*; import java.awt.BorderLayout; import java.awt.Graphics; import java.awt.Graphics2D; public class JTabbedPaneTest4 extends JFrame { Zoom zoom = null; public static void main(String[] args) { JTabbedPaneTest4 frame = new JTabbedPaneTest4(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(10, 10, 300, 200); frame.setVisible(true); } JTabbedPaneTest4() { JTabbedPane tabbedpane = new JTabbedPane(); JPanel tabPanel1 = new JPanel(); tabPanel1.add(new JButton("button1")); ImageIcon icon1 = new ImageIcon("img1.jpg"); zoom = new Zoom(icon1, 0, 0, 50, 50); //tabbedpane.addTab("tab1", icon1, tabPanel1);//ok //tabbedpane.add(zoom, tabPanel1);//ng(パネルに書き込まれてしまう) getContentPane().add(tabbedpane, BorderLayout.CENTER); } class Zoom extends JComponent { private static final long serialVersionUID = 1L; private ImageIcon icon = null; private int x = 0; private int y = 0; private int h = 0; private int w = 0; private double scale = 1.0d; public Zoom(ImageIcon icon, int x, int y, int w, int h) { super(); this.icon = icon; this.x = x; this.y = y; this.w = w; this.h = h; } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.scale(scale, scale); g2.drawImage(icon.getImage(), x, y, w, h, this); } } }

    • ベストアンサー
    • Java
  • javaでスタート画面を作っていて困っています。

    現在javaでゲームのスタート画面を作っているのですが、パネルが透過されずに困っています。 プログラムソースは import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.ImageIcon; import java.awt.Container; import java.awt.BorderLayout; import javax.swing.*; import java.awt.Font; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.ImageIcon; import java.awt.Container; import java.awt.BorderLayout; import javax.swing.border.LineBorder; import javax.swing.border.EtchedBorder; import java.awt.Color; import java.awt.Container; class Start最新版 extends JFrame{ public static void main(String args[]){ Start最新版 frame = new Start最新版("タイトル"); frame.setVisible(true); } Start最新版(String title){ setTitle(title); setBounds(10, 10, 1024, 768); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.setOpaque( false ); ImageIcon icon1 = new ImageIcon("Start.jpg"); JLabel label1 = new JLabel(icon1); JLabel label2 = new JLabel(); p.add(label1); Container contentPane = getContentPane(); contentPane.add(p, BorderLayout.CENTER); JButton button1 = new JButton("ゲームを始める"); button1.setFont(new Font("Mairyo", Font.PLAIN, 30)); JPanel n = new JPanel(); n.setOpaque(false); n.setLayout(new BoxLayout(n, BoxLayout.Y_AXIS)); n.add(Box.createRigidArea(new Dimension(290,30))); n.add(button1); となっています。「ゲームを始める」ボタンだけを残して、周りのパネルを透過して画像を表示させたいのですが、うまくいきません!解決方法をご存知の方どうか教えていただきたいです!よろしくお願いします。

  • Eclipseから実行すると画像が読み込まれない

    下記のコードをEclipseから実行すると画像が読み込まれないのですが、コマンドプロンプトから実行すると画像が読み込まれます。 コードが同じなのに不思議です…。 原因はどんなことが考えられるのでしょうか? class test extends JFrame{ public static void main(String args[]){ test frame = new test("タイトル"); frame.setVisible(true); } test(String title){ setTitle(title); setBounds(100, 100, 500, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); ImageIcon icon1 = new ImageIcon("img.jpg"); JLabel label1 = new JLabel(icon1); p.add(label1); Container contentPane = getContentPane(); contentPane.add(p, BorderLayout.CENTER); } }

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

    下記はBoxLayout用ののコードです。 Q1)Buttonのサイズを設定する方法がありますか? Q2)Buttonの配置を設定する方法がありますか? //===================================== import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.LayoutManager; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class AlignmentX extends JFrame{ JButton button1; JButton button2; JButton button3; public static void main(String[] args){ AlignmentX frame = new AlignmentX(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("タイトル"); frame.setVisible(true); } AlignmentX(){ button1 = new JButton("AAAAA"); button1.setAlignmentY(0.5f); button1.setPreferredSize(new Dimension(80,20)); button2 = new JButton("BBB"); button2.setAlignmentY(0.5f); button2.setPreferredSize(new Dimension(80,20)); button3 = new JButton("CC"); button3.setAlignmentY(0.5f); button3.setPreferredSize(new Dimension(80,20)); JPanel p = new JPanel(); p.setLayout((LayoutManager) new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(button1); p.add(button2); p.add(button3); getContentPane().add(p, BorderLayout.CENTER); setBounds(10, 10, 300, 200); } } //以上,宜しくお願いします。

    • ベストアンサー
    • Java
  • 画面を切り替えたい

    現在、ボタンを押すと 「てすと」(画像ファイル名はtest.jpg)→「てすと2」(画像ファイル名はtest2.jpg) と画面が切り替えられるプログラムを作成していますが、不明な点があり質問してみました。 2つの画面を作成してみましたが、この後どう合体すればいいのかよく分かりません。分かる方は是非教えて下さい。 <プログラムソース> (1) import java.awt.*; import java.awt.event.*; import javax.swing.*; class Title extends JFrame{ public Title() { add(new DrawPanel()); JPanel L = new DrawPanel(); L.setLayout(new BorderLayout()); JPanel L1 = new JPanel(); L1.setOpaque(false); L1.add(new JButton("OK")); L.add(L1, BorderLayout.SOUTH); setContentPane(L); } public static void main(String args[]){ JFrame frame = new Title(); frame.setSize(640, 480); frame.setTitle("てすと"); frame.setLocationRelativeTo(null); frame.setBackground(Color.pink); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);} } class DrawPanel extends JPanel{ String path = "test.jpg"; Image image; public DrawPanel() { ImageIcon icon = new ImageIcon(path); } public void paintComponent(Graphics args) { super.paintComponent(args); args.drawImage(image, 0, 0, this); args.setFont(new Font("TimesRoman",Font.ITALIC,100)); args.setColor(Color.red); args.drawString("てすと", 120, 230); } } (2) import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Title2 extends JFrame { public Title2() { add(new DrawPanel()); JPanel L = new DrawPanel(); L.setLayout(new BorderLayout()); JPanel L1 = new JPanel(); L1.setOpaque(false); L1.add(new JButton("OK")); L.add(L1, BorderLayout.SOUTH); setContentPane(L); } public static void main(String args[]){ JFrame frame = new Title2(); frame.setSize(640, 480); frame.setTitle("てすと"); frame.setLocationRelativeTo(null); frame.setBackground(Color.white); frame.setVisible(true); } } class DrawPanel extends JPanel { String path = "test2.jpg"; Image image; public DrawPanel() { ImageIcon icon = new ImageIcon(path); image = icon.getImage(); } public void paintComponent(Graphics args) { super.paintComponent(args);  args.setFont(new Font("TimesRoman",Font.BOLD,40)); args.setColor(Color.blue); args.drawString("てすと2", 150, 390); } }

    • ベストアンサー
    • Java
  • [java初心者です]ボタンのイベントの追加

    javaで、複数ボタンを表示し、クリックするとそれぞれのダイアログが表示されるプログラムを作っています。 サンプルを利用して、ボタンを追加するところまで出来たのですが そこからがうまくできません。 アクションリスナーがthisにしてあるため、どのボタンでも 同じダイアログが表示されてしまうのだと思いますが、 this以外にすることはできるのでしょうか? import javax.swing.*; import java.awt.BorderLayout; import java.awt.event.*; public class JOptionPaneTest8 extends JFrame implements ActionListener{ JLabel ansLabel; public static void main(String[] args){ JOptionPaneTest8 frame = new JOptionPaneTest8(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(10, 10, 300, 200); frame.setTitle("タイトル"); frame.setVisible(true); } JOptionPaneTest8(){ JButton ichiButton = new JButton("○○○な時"); ichiButton.addActionListener(this); JButton niButton = new JButton("○○●な時"); niButton.addActionListener(this); JPanel p = new JPanel(); p.add(ichiButton); p.add(niButton); ansLabel = new JLabel("今の気分をクリック!"); JPanel ansPanel = new JPanel(); ansPanel.add(ansLabel); getContentPane().add(p, BorderLayout.CENTER); getContentPane().add(ansPanel, BorderLayout.PAGE_END); } public void actionPerformed(ActionEvent e){ ImageIcon icon = new ImageIcon("aka.gif"); int option = JOptionPane.showConfirmDialog(this, "赤を身の回りに置いて元気に!", "OK?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, icon); if (option == JOptionPane.YES_OPTION){ ansLabel.setText("ほかには?"); }else if (option == JOptionPane.NO_OPTION){ ansLabel.setText("今の気分をクリック!"); } } 気分をボタンとして表示して そのボタンをクリックすると効果的な色のアイコン(gif)と解決策?を ダイアログとして表示させたいです。 高校でついこの間javaを始めた初心者です(>_<) 提出期限が近づいていて焦っています; お手数ですが回答お願いいたします・・・!!

  • JavaのSwingのレイアウト

    Swingを学習中ですが、うまくレイアウトできません。 添付した画像のようなレイアウトにしたいです。 作ってみたものは以下です。 import java.awt.BorderLayout; import java.awt.Color; import javax.swing.*; public class LayoutTest { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JTextField searchFiled = new JTextField("テキスト"); String[] comboboxString = {"C", "C++", "Java"}; JComboBox comboBox = new JComboBox(comboboxString); JButton button = new JButton("ボタン"); panel.add(comboBox, BorderLayout.EAST); panel.add(searchFiled, BorderLayout.CENTER); panel.add(button, BorderLayout.WEST); frame.add(panel, BorderLayout.PAGE_START); JPanel redPanel = new JPanel(); redPanel.setBackground(Color.RED); frame.add(redPanel); frame.setSize(700, 500); frame.setLocationRelativeTo(null); frame.setVisible(true); } }

    • ベストアンサー
    • Java
  • cadで作った図面をフレーム上で表示

    こんばんは いつもお世話になっています。 gif形式の図を表示することはできるのですが AutoCADで描いた図はgifファイルに出力できません。 下記のようにコーディングしたのですが、”ぜひお越しください”しか表示されませんでした。 ほかの形式(dxf、wfm、bmp)でもいろいろ試したのですができませんでした。 どうすればAutoCADで作った図をフレーム上に表示できるのでしょうか? どなたか教えていただけませんか? import java.awt.*; import javax.swing.*; import javax.swing.ImageIcon; class map { public static void main(String args[]) { JFrame frame=new JFrame("map test"); JPanel panel=new JPanel(); ImageIcon ico=new ImageIcon("地図.gif"); JButton button=new JButton("ぜひお越しください",ico); panel.add(button); Container ct=frame.getContentPane(); ct.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }

  • Eclipse3.6でSwingアプリケーションを作成しています。

    Eclipse3.6でSwingアプリケーションを作成しています。 ImageIconで画像のアドレスを登録し、画像をボタンとして使用したいのですが、画像のアドレスがフルアドレスでないとEclipse上で実行したときに画像が表示されません。 起動しているJAVAファイルと画像ファイルは同じ場所に保存してあります。 何か他の設定があるのでしょうか? 通常のJAVAコンパイル時のソース ImageIcon icon1 = new ImageIcon("./test.png"); JButton button1 = new JButton(icon1); ※このソースではEclipse上では画像が表示されない Eclipse上で起動させて時のソース ImageIcon icon1 = new ImageIcon("c:/eclipse/workspace/src/test.png"); JButton button1 = new JButton(icon1); 以上です。 宜しくお願いします。

    • ベストアンサー
    • Java