为了账号安全,请及时绑定邮箱和手机立即绑定

GridLayout JButton JOptionPane 与每个按钮的

GridLayout JButton JOptionPane 与每个按钮的

肥皂起泡泡 2021-10-28 16:57:04
我正在制作一款日本约会游戏风格的约会游戏,其中包含图片和回复,以供娱乐和练习。我正在尝试为JOptionPane网格布局中的每个按钮显示一个消息对话框,作为对每个选项的响应。这样它就像一棵逻辑树。我不习惯使用动作监听器,因为我有点初学者。这是我的代码。我只是不习惯这样做的语法。谁能帮我?import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Font;import java.awt.GridLayout;import java.util.Scanner;import javax.swing.JFrame;import javax.swing.ImageIcon;import javax.swing.JLabel;import javax.swing.*;//Implementations of packagespublic class NestedPanels extends JPanel {   private static final String[] BTN_TEXTS = { "Say Hello", "Say You Look Good", "Say Sorry I'm Late" }; //three buttons   private static final int TITLE_POINTS = 3; //number of objects in text box   public NestedPanels() { //implemeted class      JPanel southBtnPanel = new JPanel(new GridLayout(3, 2, 1, 1)); //grid layout of buttons and declaration of panel SoutbtnPanel      for (String btnText : BTN_TEXTS) { //BTN TEXT button titles linked to string btnText label         southBtnPanel.add(new JButton(btnText)); //add btnText label      }      setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); //layout of buttons "Button text"      setLayout(new BorderLayout());      add(Box.createRigidArea(new Dimension(600, 600))); //space size of text box webapp over all      add(southBtnPanel, BorderLayout.SOUTH);   }   private static void createAndShowGui() {//class to show gui        NestedPanels mainPanel = new NestedPanels(); //mainPanel new class of buttons instantiation        JFrame frame = new JFrame("Date Sim 1.0");//title of webapp on top        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);        frame.getContentPane().add(mainPanel);        frame.pack();        frame.setVisible(true);        ImageIcon icon = new ImageIcon("C:/Users/wchri/Pictures/10346538_10203007241845278_2763831867139494749_n.jpg");        JLabel label = new JLabel(icon);        mainPanel.add(label);        frame.setDefaultCloseOperation        (JFrame.EXIT_ON_CLOSE);        frame.pack();        frame.setVisible(true);   }
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信