我自己学习Java.尝试创建一个包含线条的框架.它看起来很基本,但我看不出这条线.代码编译,我似乎无法理解为什么我看不到这条线.我在框架中看到了其他组件.我正在使用2个java文件.一个文件是容器文件,另一个文件是绘制线代码.它们是包a1的一部分.这是我的代码(请帮助):
容器文件:
package a1;
import javax.swing.*;
import java.awt.*;
public class gameContainer {
public static void addComponentsToPane(Container pane) {
pane.setLayout(null);
//add button to the pane
JButton b3 = new JButton("B1");
pane.add(b3);
//add line to the pane
drawingLine line1 = new drawingLine();
pane.add(line1);
//size and position all relatively
Insets insets = pane.getInsets();
Dimension size;
size = b3.getPreferredSize();
b3.setBounds(350+insets.left,15+insets.top,size.width+50,size.height+20);
size = line1.getPreferredSize();
line1.setBounds(350+insets.left,75+insets.top,size.width+50,size.height+20);
}
private static void createAndShowGUI() {
int l = 200, w = 80;
//Create and set up the window.
JFrame …Run Code Online (Sandbox Code Playgroud)