Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用每个选项卡作为单独的类在JFrame内的选项卡中显示JPanel及其组件_Java_Swing_Jframe_Jpanel_Jtabbedpane - Fatal编程技术网

Java 使用每个选项卡作为单独的类在JFrame内的选项卡中显示JPanel及其组件

Java 使用每个选项卡作为单独的类在JFrame内的选项卡中显示JPanel及其组件,java,swing,jframe,jpanel,jtabbedpane,Java,Swing,Jframe,Jpanel,Jtabbedpane,求你了,我需要帮助。我试图创建一个包含选项卡的JFrame,每个选项卡将显示一个面板。每个面板包含按钮和文本字段。面板应在每个选项卡上显示单独的类,但面板显示时没有按钮和文本字段。任何帮助都将不胜感激 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JFrame; public class CELTool extends JFrame implements ActionLi

求你了,我需要帮助。我试图创建一个包含选项卡的
JFrame
,每个选项卡将显示一个面板。每个面板包含按钮和
文本字段
。面板应在每个选项卡上显示单独的类,但面板显示时没有按钮和
文本字段。任何帮助都将不胜感激

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFrame;

public class CELTool extends JFrame implements ActionListener {

   JTabbedPane tab;

   public CELTool() {
      JFrame frame = new JFrame("CELTool");
      tab = new JTabbedPane();
      frame.add(tab, BorderLayout.CENTER);

      Illustration etool = new Illustration();
      tab.add("Illustration", etool);

      Encrypt crypt = new Encrypt();
      tab.add("Crypt", crypt);

      Decrypt decrypt = new Decrypt();

      tab.add("Decrypt", decrypt);

      frame.setSize(500, 750);
      frame.pack();
      frame.setVisible(true);
      frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

   }

   public void actionPerformed(ActionEvent ae) {
   }

   public static void main(String[] args) {
      CELTool clt = new CELTool();//        
      clt.setSize(400,500);     
      clt.setVisible(true);
   }
}

class Illustration extends JPanel {

   static String[] strPlaintext = {"Original Input", "InitialPermutation", "First RIound ", "Second Round",
                                   "Third Round", "Fourth Round", "Fifth Round", "Sixth Round", "Seventh Round",
                                   "Eight Round", "Ninth Round", "Tenth Round", "Eleventh Round", "Twelveth Round",
                                   "Thirteenth Round", "Fourtheenth Round", "Fithteenth Round", "Sixtheenth Round",
                                   "Final Round", "Ciphertext"};
   static String[] str2 = {"Key", "Round Sixteen", "Round Fithteen", "Round Fourteen", "Round Thirteen", "Round Twelve",
                           "Round Eleven", "Round Ten",};
   int leading, ascent, height, width;
   int leading2, ascent2, height2, width2;
   int xcoord = 40, ycoord = 100, xcoord2 = 600, ycoord2 = 60;
   static final int BORDER = 5;

   public void paint(Graphics gr) {
      super.paint(gr);
      int i = 0, xcoord = 40, ycoord = 100, xcoord2 = 600, ycoord2 = 60;


      leading = gr.getFontMetrics().getLeading();
      ascent = gr.getFontMetrics().getAscent();
      height = gr.getFontMetrics().getHeight();
      width = gr.getFontMetrics().stringWidth(strPlaintext[i]);

      for (i = 0; i < strPlaintext.length; i++) {
         gr.drawString(strPlaintext[i], xcoord, ycoord);
         leading = gr.getFontMetrics().getLeading();
         ascent = gr.getFontMetrics().getAscent();
         height = gr.getFontMetrics().getHeight();
         width = gr.getFontMetrics().stringWidth(strPlaintext[i]);
         gr.drawRect(xcoord - BORDER, ycoord - (ascent + leading + BORDER), width + 2 * BORDER, height + 2 * BORDER);
         ycoord += 40;

      }

   }
}

class Encrypt extends JPanel {

   public Encrypt() {
      JPanel panel5 = new JPanel();
      panel5.setLayout(new GridBagLayout());    //panel5.setLayout((LayoutManager) new GridBagConstraints());

      GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      panel5.add(new JLabel("Input plaintext text"), gbc);

      gbc.gridx = 1;
      gbc.gridy = 0;
      panel5.add(new JTextField("0123456789ABCDEF", 20), gbc);

      gbc.gridx = 0;
      gbc.gridy = 2;
      panel5.add(new JLabel("Input text in Hex"), gbc);

      gbc.gridx = 1;
      gbc.gridy = 2;
      panel5.add(new JTextField("0123456789ABCDEF", 20), gbc);

      panel5.setSize(200, 300);
      panel5.setVisible(true);
   }
}

class Decrypt extends JPanel {

   JPanel decPanel;
   JTextField dectxt;

   public Decrypt() {
      decPanel = new JPanel();
      decPanel.add(new JLabel("Cipher"));
      decPanel.add(new JTextField());
      decPanel.add(new JLabel("key"));
      decPanel.add(new JTextField());
      decPanel.add(new JLabel("Plaintext"));
      decPanel.add(new JTextField());
      decPanel.add(new JButton("Decrypt"));
      decPanel.add(new JButton("Reset"));
      decPanel.validate();

   }
}
import java.awt.*;
导入java.awt.event.*;
导入javax.swing.*;
导入javax.swing.JFrame;
公共类CELTool扩展JFrame实现ActionListener{
JTabbedPane选项卡;
公共工具(){
JFrame=新JFrame(“CELTool”);
tab=新的JTabbedPane();
添加框架(选项卡,边框布局。中心);
插图etool=新插图();
添加(“插图”,etool);
Encrypt crypt=new Encrypt();
添加(“Crypt”,Crypt);
Decrypt Decrypt=新解密();
添加(“解密”,解密);
框架设置尺寸(500750);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(关闭时退出);
}
已执行的公共无效行动(行动事件ae){
}
公共静态void main(字符串[]args){
CELTool clt=新CELTool();//
clt.setSize(400500);
clt.setVisible(真);
}
}
类插图扩展了JPanel{
静态字符串[]strPlaintext={“原始输入”、“初始置换”、“第一轮”、“第二轮”,
“第三轮”、“第四轮”、“第五轮”、“第六轮”、“第七轮”,
“第八轮”、“第九轮”、“第十轮”、“第十一轮”、“第十二轮”,
“第十三轮”、“第四轮”、“第十四轮”、“第六轮”,
“最后一轮”、“密文”};
静态字符串[]str2={“Key”,“Round十六”,“Round fitteen”,“Round十四”,“Round十三”,“Round十二”,
“第十一轮”、“第十轮”};
内部引导、上升、高度、宽度;
内部引线2,上升2,高度2,宽度2;
int xcoord=40,ycoord=100,xcoord2=600,ycoord2=60;
静态最终整型边界=5;
公共空间涂料(图形gr){
超级油漆(gr);
int i=0,xcoord=40,ycoord=100,xcoord2=600,ycoord2=60;
leading=gr.getFontMetrics().getLeading();
ascent=gr.getFontMetrics().getAscent();
高度=gr.getFontMetrics().getHeight();
width=gr.getFontMetrics().stringWidth(strPlaintext[i]);
对于(i=0;i
这根本不是一个完整的解决方案,但至少可以让您朝着正确的方向前进。仔细地将其与代码进行比较,以查看差异。希望这有帮助

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFrame;

public class CELTool extends JFrame implements ActionListener {

   JTabbedPane tab;
   Illustration etool;
   Encrypt encrypt;
   Decrypt decrypt;

   private CELTool() {
      super("CELTool");

      tab = new JTabbedPane();
      etool = new Illustration();
      encrypt = new Encrypt();
      decrypt = new Decrypt();

      tab.add("Illustration", etool);
      tab.add("Crypt", encrypt);
      tab.add("Decrypt", decrypt);
      this.add(tab, BorderLayout.CENTER);

      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
      this.setSize(500, 750);
      this.pack();
      this.setLocationRelativeTo(null);
      this.setVisible(true);
   }

   public void actionPerformed(ActionEvent ae) {
      // why blank?
   }

   public static void main(String[] args) {
      new CELTool();      
   }


private class Illustration extends JPanel {

   public Illustration(){

   }

   private final String[] strPlaintext = {"Original Input", "InitialPermutation", "First RIound ", "Second Round",
                                   "Third Round", "Fourth Round", "Fifth Round", "Sixth Round", "Seventh Round",
                                   "Eight Round", "Ninth Round", "Tenth Round", "Eleventh Round", "Twelveth Round",
                                   "Thirteenth Round", "Fourtheenth Round", "Fithteenth Round", "Sixtheenth Round",
                                   "Final Round", "Ciphertext"};
   private final String[] str2 = {"Key", "Round Sixteen", "Round Fithteen", "Round Fourteen", "Round Thirteen", "Round Twelve",
                           "Round Eleven", "Round Ten",};
   int leading, ascent, height, width;
   int xcoord = 40, ycoord = 100, xcoord2 = 600, ycoord2 = 60;
   private final int BORDER = 5;

   public void paintComponent(Graphics gr) {
      super.paintComponent(gr);
      int i = 0, xcoord = 40, ycoord = 100, xcoord2 = 600, ycoord2 = 60;

      leading = gr.getFontMetrics().getLeading();
      ascent = gr.getFontMetrics().getAscent();
      height = gr.getFontMetrics().getHeight();

      for (i = 0; i < strPlaintext.length; i++) {
         gr.drawString(strPlaintext[i], xcoord, ycoord);
         width = gr.getFontMetrics().stringWidth(strPlaintext[i]);
         gr.drawRect(xcoord - BORDER, ycoord - (ascent + leading + BORDER), width + 2 * BORDER, height + 2 * BORDER);
         ycoord += 40;
      }
   }
}

private class Encrypt extends JPanel {

   public Encrypt() {
      this.setLayout(new GridBagLayout());
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      this.add(new JLabel("Input plaintext text"), gbc);

      gbc.gridx = 1;
      gbc.gridy = 0;
      this.add(new JTextField("0123456789ABCDEF", 20), gbc);

      gbc.gridx = 0;
      gbc.gridy = 2;
      this.add(new JLabel("Input text in Hex"), gbc);

      gbc.gridx = 1;
      gbc.gridy = 2;
      this.add(new JTextField("0123456789ABCDEF", 20), gbc);

      this.setPreferredSize(new Dimension(200, 300));
   }
}

private class Decrypt extends JPanel {

   public Decrypt() {
      this.setLayout(new GridLayout(0,1));
      this.add(new JLabel("Cipher"));
      this.add(new JTextField());
      this.add(new JLabel("key"));
      this.add(new JTextField());
      this.add(new JLabel("Plaintext"));
      this.add(new JTextField());
      this.add(new JButton("Decrypt"));
      this.add(new JButton("Reset"));
      this.validate();
   }
 }
}
import java.awt.*;
导入java.awt.event.*;
导入javax.swing.*;
导入javax.swing.JFrame;
公共类CELTool扩展JFrame实现ActionListener{
JTabbedPane选项卡;
乙醇;
加密;
解密;
私人工具(){
超级(“CELTool”);
tab=新的JTabbedPane();
etool=新插图();
encrypt=newencrypt();
解密=新的解密();
添加(“插图”,etool);
添加(“加密”,加密);
添加(“解密”,解密);
添加(选项卡,BorderLayout.CENTER);
此.setDefaultCloseOperation(关闭时退出);
这个。设置大小(500750);
这个包();
此.setLocationRelativeTo(空);
此.setVisible(true);
}
已执行的公共无效行动(行动事件ae){
//为什么是空白?
}
公共静态void main(字符串[]args){
新工具();
}
私有类扩展了JPanel{
公共插图(){
}
私有的最终字符串[]strPlaintext={“原始输入”、“初始置换”、“第一轮”、“第二轮”,
“第三轮”、“第四轮”、“第五轮”、“第六轮”、“第七轮”,
“第八轮”、“第九轮”、“第十轮”、“第十一轮”、“第十二轮”,
“第十三轮”、“第四轮”、“第十四轮”、“第六轮”,
“最后一轮”、“密文”};
私人决赛