So, BuildAssessmentWindow is supposed to have a space in it for adding another JPanel in the center of the BorderLayout.
I wanted that panel to be made in a different file. What am I supposed to do within that other file to make it work correctly? Right now it's giving me a bunch of errors.
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
// imports for window components
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JComboBox;
public class QuestionBlock extends JFrame
{
private JPanel container;
private JPanel number;
private JPanel questionBlock;
private JPanel questionPanel;
private JPanel answer;
private JComboBox numberDropDown, answerDropDown;
private JTextArea question;
JPanel container = new JPanel();
container.setLayout(new BorderLayout());
JPanel number = new JPanel();
numberDropDown = new JComboBox;
numberDropDown.addItem("1.");
numberDropDown.addItem("a.");
number.add(numberDropDown);
container.add(number, BorderLayout.LINE_START);
JPanel questionBlock = new JPanel();
questionBlock.setLayout(new BorderLayout());
container.add(questionBlock, BorderLayout.CENTER);
JPanel questionPanel = newJPanel();
question = new JTextArea(4, 10);
questionBlock.add(questionPanel, BorderLayout.PAGE_START);
JPanel answer = new JPanel();
answerDropDown = new JComboBox;
answerDropDown.addItem("--Select--");
questionBlock.add(answer, BorderLayout.PAGE_END);
public JPanel getPanel()
{
return container;
}
}
This is the main file:
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
// imports for window components
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
// imports for listeners
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
// imports for background colors
import java.awt.Color;
//import java.awt.Container;
// imports for component alignments
import java.awt.Component;
// // imports for text editability
//import javax.swing.text.StyledEditorKit;
// // imports for component focus control
//import java.awt.KeyboardFocusManager;
public class BuildAssessmentWindow extends JFrame implements ActionListener,
FocusListener
{
public static final int WIDTH = 400;
public static final int HEIGHT = 350;
private JPanel titlePanel;
private JPanel titleTopPanel;
private JPanel titleBottomPanel;
private JPanel questionsPanel;
private JPanel savePanel;
private boolean changedTitle = false;
private JLabel introLabel;
private JTextArea leftExtra, centerExtra, rightExtra;
private JTextField assessmentTitle;
private JButton questionButton, saveButton;
public JTextArea question;
//private Container contentPane;
public BuildAssessmentWindow()
{
super("Build Assessment");
setSize(WIDTH, HEIGHT);
getContentPane().setBackground(Color.WHITE);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
titlePanel = new JPanel();
titlePanel.setBackground(Color.WHITE);
titlePanel.setLayout(new GridLayout(2, 1));
titleTopPanel = new JPanel();
titleTopPanel.setBackground(Color.WHITE);
titleTopPanel.setLayout(new FlowLayout());
titleBottomPanel = new JPanel();
titleBottomPanel.setBackground(Color.WHITE);
titleBottomPanel.setLayout(new FlowLayout());
leftExtra = new JTextArea(2, 10);
leftExtra.setBackground(new Color(250, 250, 250));
// leftExtra.setHorizontalAlignment(JTextArea.LEFT);
leftExtra.setAlignmentX(Component.LEFT_ALIGNMENT);
titleTopPanel.add(leftExtra);
centerExtra = new JTextArea("type whatever you like here", 2, 10);
centerExtra.setBackground(new Color(250, 250, 250));
// centerExtra.setHorizontalAlignment(JTextArea.CENTER);
centerExtra.addFocusListener(this);
centerExtra.setAlignmentX(Component.CENTER_ALIGNMENT);
titleTopPanel.add(centerExtra);
rightExtra = new JTextArea(2, 10);
rightExtra.setBackground(new Color(250, 250, 250));
// rightExtra.setHorizontalAlignment(JTextArea.RIGHT);
rightExtra.setAlignmentX(Component.RIGHT_ALIGNMENT);
titleTopPanel.add(rightExtra);
assessmentTitle = new JTextField("Assessment Title", 10);
assessmentTitle.addFocusListener(this);
titleBottomPanel.add(assessmentTitle);
titlePanel.add(titleTopPanel);
titlePanel.add(titleBottomPanel);
add(titlePanel, BorderLayout.PAGE_START);
savePanel = new JPanel();
savePanel.setLayout(new FlowLayout());
saveButton = new JButton("Save assessment");
saveButton.addActionListener(this);
savePanel.add(saveButton);
add(savePanel, BorderLayout.PAGE_END);
// requestFocusInWindow();
}
public static void main(String[] args)
{
BuildAssessmentWindow gui = new BuildAssessmentWindow();
// getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
gui.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
getQandAPanel();
}
public void focusGained(FocusEvent e)
{
if(!changedTitle)
{
assessmentTitle.setText("");
changedTitle=true;
}
}
public void focusLost(FocusEvent e)
{
}
public void getQandAPanel()
{
JPanel block = new JPanel
QuestionBlock questionPanel = new QuestionBlock();
block=questionPanel.getPanel();
add(block, BorderLayout.CENTER);
// JPanel questionPanel = new JPanel();
// JPanel answerPanel = new JPanel();
// JPanel questionBoxPanel = new JPanel();
// question=new JTextArea(4, 10);
// questionPanel.add(question);
// questionsPanel.add(questionPanel);
// questionsPanel.add(answerPanel);
// questionsPanel.revalidate();
// questionsPanel.repaint();
}
}

New Topic/Question
Reply



MultiQuote




|