I made a simple program to gain my knowledge and test my knowledge.
it's kinda like a MCQ paper. I only added one question to it I used Netbeans but I only used it as a text editor because I like it. I didn't use any other feature of it. Because if I use them I would forget so many important stuff because I am a student not a professional programmer.
Here is a screenshot of the program Not very complicated or advance one just a simple one
Here is the source.
GUI.java
Code: Select all
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUI extends JFrame implements ActionListener {
private JLabel display,ans1,ans2;
private JTextField input;
private JButton actionButton;
private String location[] = {"q.jpg","ans1.jpg","ans2.jpg"};
private Icon images[] = {new ImageIcon(getClass().getResource(location[0])),
new ImageIcon(getClass().getResource(location[1])),
new ImageIcon(getClass().getResource(location[2]))
};
private JPanel leftPanel,rightPanel,bottomPanel;
public GUI(){
super("Quiz Paper");
setSize(350,240);
display = new JLabel();
display.setIcon(images[0]);
leftPanel = new JPanel();
leftPanel.setBackground(Color.BLUE);
leftPanel.add(display, BorderLayout.CENTER);
add(leftPanel, BorderLayout.WEST);
ans1 = new JLabel(images[1]);
ans2 = new JLabel(images[2]);
rightPanel = new JPanel();
rightPanel.add(ans1);
rightPanel.add(ans2);
rightPanel.setBackground(Color.BLUE);
add(rightPanel, BorderLayout.CENTER);
input = new JTextField("Type the answer 1 or 2");
actionButton = new JButton("Click to check the answer");
actionButton.addActionListener(this);
bottomPanel = new JPanel();
bottomPanel.add(input);
bottomPanel.add(actionButton);
add(bottomPanel, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event){
try{
int answer = Integer.parseInt(input.getText());
if(answer == 1)
JOptionPane.showMessageDialog(null,"Your Answer is Correct!!!" ,"Your Status" ,JOptionPane.PLAIN_MESSAGE);
else if(answer == 2)
JOptionPane.showMessageDialog(null, "Your Answer is Wrong!!", "Your Status",JOptionPane.PLAIN_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Try Again!!", "Your Status",JOptionPane.PLAIN_MESSAGE);
}
catch(Exception e){
}
}
}
Code: Select all
import javax.swing.JFrame;
public class Quiz_Paper_Main{
public static void main(String args[]){
GUI gui = new GUI();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setVisible(true);
}
}
Oh almost forgot, I am adding the source too, So it maybe useful to somebody else. (It has, Source files, Images and .class files)
Thanks
PS. I like to know your ideas about this