我是这里的新手,我正在使用Java的桌面用户界面来处理应用程序。 ...但是我创建了6个不同的接口,它们应该能够相互链接......每个接口都单独运行,因为它们有自己的主方法。 ..并且每个教程和Web研究都会导致“如何链接一个主类和一个子类”。 ...我的问题是是否可以使用自己的main方法链接两个java类?如果是这样,有人可以指导我将其纳入我的代码??? 其中一个接口如下..
//start
/*
* To change this license header, choose
License Headers in Project Properties.
* To change this template file, choose
Tools | Templates
* and open the template in the editor.
*/
package spackage;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
public class Path2_Test1 extends
javax.swing.JFrame {
/** Creates new form Path2_Test1 */
public Path2_Test1() {
//create a panel for the 4 buttons
JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(4,1,0,20));
p2.setBackground(Color(217,63,49));
//add buttons to be customized later
JButton addDoc = new JButton("ADD
DOCUMENT");
JButton viewDb = new JButton("VIEW
DATABASE");
JButton ask = new JButton("ASK");
JButton about = new JButton("ABOUT");
// set color
addDoc.setBackground(Color(217,63,49));
viewDb.setBackground(Color(217,63,49));
ask.setBackground(Color(217,63,49));
about.setBackground(Color(217,63,49));
// add border
Border lineBorder = new
LineBorder(Color.WHITE, 3);
addDoc.setBorder(lineBorder);
viewDb.setBorder(lineBorder);
ask.setBorder(lineBorder);
about.setBorder(lineBorder);
//set foreground color
addDoc.setForeground(Color.WHITE);
viewDb.setForeground(Color.WHITE);
ask.setForeground(Color.WHITE);
about.setForeground(Color.WHITE);
// add to panel
p2.add(addDoc);
p2.add(viewDb);
p2.add(ask);
p2.add(about);
JPanel p1 = new JPanel();
// new border layout with hgap =5 and
vgap =10
p1.setLayout(new
BorderLayout(50,50));
p1.setBackground(Color(217,63,49));
//add north, ease, west, and south
buttons with no labels to make a rigid
space
p1.add(new JLabel(""),
BorderLayout.EAST);
p1.add(new JLabel(""),
BorderLayout.WEST);
p1.add(new JLabel(""),
BorderLayout.NORTH);
p1.add(new JLabel(""),
BorderLayout.SOUTH);
p1.add(p2, BorderLayout.CENTER);
//add contents to the frame
add(p1, BorderLayout.CENTER);
}
/** This method is called from within the
constructor to
* initialize the form.
* WARNING: Do NOT modify this code.
The content of this method is
* always regenerated by the Form
Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed"
desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout
(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
Path2_Test1 frame = new Path2_Test1();
frame.setBackground(Color.ORANGE);
frame.setTitle("");
frame.setSize(400,300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setVisible(true);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try
{
Thread.sleep(4500);
}
catch(Exception e){
}
//new Path2_Test1().setVisible(true);
frame.setBackground(Color.ORANGE);
frame.setTitle("");
frame.setSize(400,300);
//frame.setResizeable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
private Color Color(int r, int g, int b) {
Color c1 = new Color(217,63,49);
return c1;
// Variables declaration - do not modify
// End of variables declaration
}
}// end of code
链接到这个的另一个界面如下...... 它在点击上面界面中的“查看数据库”按钮时被调用
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package spackage;
/**
*
* @author Eskias.Y
*/
import javax.swing.*;
import java.awt.*;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
public class Path_5_1 extends JFrame{
JPanel p = new JPanel();
JTextArea textP5 = new JTextArea();
JScrollPane textP5Scroll = new JScrollPane(
textP5,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
public static void main(String[] args){
new Path_5_1();
}
public Path_5_1(){
super("Triples");
setSize(400,800);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
p.setLayout(new BorderLayout());
//set center
Border lineBorder = new LineBorder(new Color(196,69,36),5);
textP5.setBorder(lineBorder);
textP5.setBackground(new Color(200,183,154));
textP5.setForeground(Color.BLACK);
textP5.setEditable(false);
p.add(textP5, BorderLayout.CENTER);
add(p);
setVisible(true);
}
}// end of code
任何人都可以帮助我,因为我几乎被困在这里? ?? 提前谢谢....