大家好,我正在从这个站点学习 java。我想在不放 main 的情况下制作 java 文件,以便与其他文件连接。我的意思是我想做这个子文件。那么你们能帮我从这个文件中删除主要内容并运行它吗?
这是我的代码
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/* ColorChooserDemo.java requires no other files. */
public class jptborder extends JPanel{
protected JColorChooser tcc;
protected JLabel banner;
public jptborder() {
super(new BorderLayout());
//Set up the banner at the top of the window
banner = new JLabel("Welcome To this border Example",
JLabel.CENTER);
banner.setForeground(Color.red);
//banner.setBackground(Color.blue);
banner.setOpaque(true);
banner.setFont(new Font("Arial", Font.BOLD, 24));
banner.setPreferredSize(new Dimension(450, 65));
JPanel bannerPanel = new JPanel(new BorderLayout());
bannerPanel.add(banner, BorderLayout.CENTER);
bannerPanel.setBorder(BorderFactory.createTitledBorder("Welcome"));
add(bannerPanel, BorderLayout.CENTER);
}
public static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("jptBorder");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new jptborder();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}