Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Swing plugin for Eclipse
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jacks, post: 3702526, member: 53501"] [b]Chakri[/b] package com.applabs.exams.scjpmock; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; public class QuestionScreen extends JPanel{ private JLabel lblName; private JLabel lblExam; private JTextField txtName; private JTextField txtExam; private JButton btnPrevious; private JButton btnNext; private JTextArea question; private JCheckBox[] ckbOptions; private static String NAME = "Name :"; private static String EXAM = "Exam :"; private static String PREVIOUS ="<-Previous"; private static String NEXT = "NEXT->"; private static String QUESTION = "Question"; private static String COLON = ": "; private static int NO_OF_CHOICES = 4; private static String[] CHOICES = {"Option One","Option two","Option three","Option four"}; private static String FILE = "File"; private static String EXIT = "Exit"; private static String HELP = "Help"; private static String OF = "of"; //TODO Add timer component // private JLabel timeLeft; // private JSpinner time; // private static String TIMELEFT = "Time Left :"; // timeLeft = new JLabel(TIMELEFT); // time = new JSpinner(new SpinnerDateModel()); public QuestionScreen() { init(); // createControls(); addControls(); } private void init() { // TODO Auto-generated method stub lblName = new JLabel(NAME); lblExam = new JLabel(EXAM); txtName = new JTextField(20); txtName.setEditable(false); txtName.setOpaque(false); txtExam = new JTextField(20); txtExam.setEditable(false); txtExam.setOpaque(false); btnPrevious = new JButton(PREVIOUS); btnNext = new JButton(NEXT); question = new JTextArea(5,60); /*optnOne = new JCheckBox(); optnTwo = new JCheckBox(); optnThree = new JCheckBox(); optnFour = new JCheckBox();*/ } public void addControls() { // JPanel mainPanle = new JPanel(); // mainPanle.setLayout(new BorderLayout()); JPanel topLeftPane = new JPanel(); topLeftPane.add(lblName); topLeftPane.add(txtName); JPanel topRightPane = new JPanel(); topRightPane.add(lblExam); topRightPane.add(txtExam); JPanel topPane = new JPanel(new BorderLayout()); topPane.add(topLeftPane,BorderLayout.WEST); topPane.add(topRightPane,BorderLayout.EAST); topPane.add(new JLabel(QUESTION + COLON), BorderLayout.SOUTH); JPanel midPane = new JPanel(new BorderLayout()); JPanel questionPnl = new JPanel(new BorderLayout()); questionPnl.add(question,BorderLayout.CENTER); //TODO get the total choices of the question and place it here //For temp purpose we are using 4 as default ckbOptions = new JCheckBox[NO_OF_CHOICES]; JPanel optionPnl = new JPanel(); optionPnl.setLayout(new BoxLayout(optionPnl, BoxLayout.Y_AXIS)); int idx=0; for(int i=0;i< NO_OF_CHOICES; i++) { ckbOptions[i] = new JCheckBox(CHOICES[i]); optionPnl.add(Box.createHorizontalGlue()); optionPnl.add(ckbOptions[i]); } // JPanel leftMidSouth = new JPanel(new BorderLayout()); // leftMidSouth.add(optnOne, BorderLayout.NORTH); // leftMidSouth.add(optnThree, BorderLayout.SOUTH); // // JPanel rtMidSouth = new JPanel(new BorderLayout()); // rtMidSouth.add(optnTwo, BorderLayout.NORTH); // rtMidSouth.add(optnFour,BorderLayout.SOUTH); // multipleChoicesPnl.add(leftMidSouth,BorderLayout.WEST); // multipleChoicesPnl.add(rtMidSouth,BorderLayout.EAST); midPane.add(questionPnl, BorderLayout.CENTER); midPane.add(optionPnl, BorderLayout.SOUTH); JPanel generalInfo = new JPanel(new BorderLayout()); //TODO replace 5 and 10 with the actual values generalInfo.add(new JLabel(QUESTION + "5" + OF + "10"),BorderLayout.WEST); generalInfo.add(new JLabel("Display time component"),BorderLayout.EAST); JPanel buttonsPnl = new JPanel(new BorderLayout()); buttonsPnl.add(btnPrevious, BorderLayout.WEST); buttonsPnl.add(btnNext, BorderLayout.EAST); buttonsPnl.add(generalInfo, BorderLayout.SOUTH); this.setLayout(new BorderLayout()); this.add(topPane,BorderLayout.NORTH); this.add(midPane, BorderLayout.CENTER); this.add(buttonsPnl, BorderLayout.SOUTH); // this.setLayout(new BorderLayout()); // this.add(mainPanle, BorderLayout.CENTER); // return pane; } public JMenuBar addMenu() { JMenuItem newItem,openItem,exitItem,saveItem; JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu(FILE); fileMenu.setMnemonic(KeyEvent.VK_F); exitItem = new JMenuItem(EXIT); exitItem.setMnemonic(KeyEvent.VK_X); fileMenu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.exit(0); } }); JMenu helpMenu = new JMenu(HELP); helpMenu.setMnemonic(KeyEvent.VK_H); menuBar.add(fileMenu); menuBar.add(helpMenu); return menuBar; } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(600, 450); frame.setTitle("SCJP Mock Exam"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); QuestionScreen questionUI = new QuestionScreen(); frame.add(questionUI); frame.setJMenuBar(questionUI.addMenu()); frame.setVisible(true); } }[/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Swing plugin for Eclipse
Top