所以我有兩個類:JTextArea&JPanel不同的類一個窗口...有可能嗎?
public class TimeServer extends JPanel implements TimeVariables
{
public TimeServer()
{
JTextArea serverLog = new JTextArea();
// Create a scroll pane to hold text area
JScrollPane scrollPane = new JScrollPane(serverLog);
JPanel serverWin = new JPanel();
serverWin.add(scrollPane);
}
而且具有其他類:
private JPanel mainWin = new JPanel();
private JPanel gridArea = new JPanel(); //hold cells
TimeServer serverWin = new TimeServer();
public class TimClient extends JFrame implements Runnable, TimeVariables
{
his.add(mainWin, BorderLayout.CENTER);
mainWin.setLayout(new BorderLayout());
// mainWin.setLayout(new GridLayout(1,2));
//Create Grid
gridArea.setLayout(new GridLayout(10, 10, 2, 2));
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
gridArea.add(cell[i][j] = new Cell(i, j, this));
gridArea.setBorder(new LineBorder(Color.black, 1));
jlblTitle.setHorizontalAlignment(JLabel.CENTER);
jlblTitle.setFont(new Font("SansSerif", Font.BOLD, 16));
jlblTitle.setBorder(new LineBorder(Color.black, 1));
jlblStatus.setBorder(new LineBorder(Color.black, 1));
mainWin.add(gridArea, BorderLayout.CENTER);
mainWin.add(serverWin, BorderLayout.PAGE_END);
// Place the panel and the labels to the frame
setLayout(new BorderLayout()); // implicit anyway
add(jlblTitle, BorderLayout.NORTH);
add(mainWin, BorderLayout.CENTER);
add(jlblStatus, BorderLayout.SOUTH);
}
public static void main(String[] args) {
// Create a frame
TimClient frame = new TimClient("Time Client");
//frame.getContentPane().add(BorderLayout)
// Display the frame
frame.setSize(620, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
所有我想要做的是保持在JPanel的服務器日誌和網格彼此相鄰,能你解釋如何?
也我如何將服務器類中的JPanel添加到客戶端中的JPanel?
這裏有一個如何我想它看起來草圖:上面
刪除問題的內容將不會幫助任何其他人在未來... – MadProgrammer