Advertisement
gdog2u

GuiLayout

Mar 24th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1.     JButton startBtn = new JButton("Start");
  2.     JButton answerBtn = new JButton("Answer");
  3.     JButton nextBtn = new JButton("Next");
  4.    
  5.     TextArea questionTA = new TextArea("Welcome to the challenge Mode", 4,30, TextArea.SCROLLBARS_VERTICAL_ONLY);
  6.    
  7.     TextField answerTF = new TextField(10);
  8.     TextField responseTF = new TextField(10);
  9.     TextField rightTF =new TextField("0", 2);
  10.     TextField wrongTF = new TextField("0", 2);
  11.     TextField scoreTF = new TextField(3);
  12.    
  13.     int numRight = 0;
  14.     int numWrong = 0;
  15.     int questionNumber = 0;
  16.    
  17.     JLabel scoreLbl= new JLabel("Score: ");
  18.     JLabel pointsLbl = new JLabel("Points: ");
  19.     JLabel rightLbl = new JLabel("Correct: ");
  20.     JLabel wrongLbl = new JLabel("Wrong: ");
  21.  
  22.         JFrame w = new JFrame();
  23.         JPanel p = new JPanel();
  24.        
  25.         w.setSize(300,350);
  26.         w.setTitle("Challenge Mode");
  27.         w.setLocationRelativeTo(null);
  28.         w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  29.         w.setVisible(true);
  30.        
  31.         p.setLayout(new FlowLayout());
  32.         p.add(startBtn);
  33.             startBtn.addActionListener(this);
  34.         //p.add(Box.createHorizontalStrut(80));
  35.         //next line
  36.         p.add(questionTA);
  37.             questionTA.setEditable(false);
  38.         //p.add(Box.createHorizontalStrut(80));
  39.         //next line
  40.         p.add(answerTF);
  41.         //p.add(Box.createHorizontalStrut(90));
  42.         //next line
  43.         p.add(answerBtn);
  44.             answerBtn.addActionListener(this);
  45.         p.add(Box.createHorizontalStrut(60));
  46.         p.add(responseTF);
  47.         p.add(nextBtn);
  48.             nextBtn.addActionListener(this);
  49.         p.add(Box.createHorizontalStrut(70));
  50.         //next line
  51.         p.add(pointsLbl);
  52.         p.add(Box.createHorizontalStrut(20));
  53.         p.add(scoreLbl);
  54.         p.add(scoreTF);
  55.         p.add(Box.createHorizontalStrut(90));
  56.         //next line
  57.         p.add(rightLbl);
  58.         p.add(rightTF);
  59.         p.add(wrongLbl);
  60.         p.add(wrongTF);
  61.         w.add(p);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement