Dashboard

Container frameContainer = dashboardFrame.getContentPane();
frameContainer.setBackground(Color.gray);
// Changeable According to What size of screen You Want?
int containerWidth = windowWidth*94/100;
int containerHeight = windowHeight*90/100;
int panelWidth = containerWidth*96/100;
int panelHeight = containerHeight*94/100;
int posX = windowWidth / 2 - panelWidth / 2 - windowWidth / 120;
int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;
// frame without control options
JPanel panel = new JPanel();
panel.setLayout(null);//new BorderLayout());
panel.setBackground(Color.WHITE);
panel.setSize(new Dimension(panelWidth,panelHeight));
panel.setLocation(posX, posY);
frameContainer.add(panel);
After creation of window, we will add a canvas background.
// for Rounded Background
posX = windowWidth / 2 - containerWidth / 2;
posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
JComponent jcomponent = new RoundedBackground(posX, posY, containerWidth, containerHeight);
jcomponent.setLayout(null);
frameContainer.add(jcomponent, BorderLayout.CENTER);
public class RoundedBackground extends JComponent {
private static final long serialVersionUID = 1L;
int width, height,setX,setY;
public RoundedBackground (int setX,int setY,int width, int height) {
this.width=width;
this.height=height;
this.setX=setX;
this.setY=setY;
setSize(width, height);
}
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.white);
double x = setX;
double y = setY;
double w = width;
double h = height;
RoundRectangle2D round=new RoundRectangle2D.Double(x, y, w, h, 80, 80);
g2.fill(round);
}
}
public class SQLiteJDBCDriverConnection {
/**
* Connect to a sample database
*/
public static Connection connect() {
try {
// SQLite connection string
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException ex) {
Logger.getLogger(SQLiteJDBCDriverConnection.class.getName()).log(Level.SEVERE, null, ex);
}
String url = "jdbc:sqlite:quiz_db.db";
Connection conn = null;
try {
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
}
Here we Create Header and Logout Layout.
// for heading Layout
posX = 0;
posY = 0;
font = new Font("Lucida", Font.PLAIN, 48);
JPanel header = Util.createPanel(panelWidth, panelHeight/10, posX,posY, "Quiz", true, Color.white, font);
panel.add(header);
header.setLayout(null);
// logout bar
posX = 0;
posY = (int) (panelHeight * 11/100);
font = new Font("Lucida", Font.PLAIN, 48);
JPanel logoutBar = createLogoutBar(panelWidth, panelHeight/12, posX,posY, "", false, Color.black, font);
panel.add(logoutBar);
logoutBar.setLayout(null);
Here logout UI and logic for logout when click "LOGOUT" Button.
private JPanel createLogoutBar(int width, int height,int posX, int posY, String titelName, boolean isFill, Color color, Font font) {
final JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setEnabled(true);
panel.setSize(new Dimension(width, height));
panel.setLocation(posX, posY);
JSeparator topBorder = new JSeparator();
topBorder.setBackground(Color.BLACK);
topBorder.setBounds(0, 1, width, 2);
panel.add(topBorder);
int labelWidth = width*20/100;
int labelHeight = height*50/100;
int pX = width*3/100;
int pY = labelHeight/2 ;
font = new Font("Lucida",Font.PLAIN,12);
JLabel user_name=new JLabel();
user_name.setText("Hi, "+ AppConstant.USER_NAME);
user_name.setForeground(Color.black);
user_name.setFont(font);
user_name.setSize(new Dimension(labelWidth,labelHeight));
user_name.setLocation(pX, pY);
panel.add(user_name);
int btnWidth = width * 10/100;
int btnHeight = height * 50/100;
pX = width- btnWidth - width*3/100;
pY = btnHeight/2 ;
Font btnFont = new Font("Lucida",Font.PLAIN,12);
JButton loginBtn = new JButton("Login");
loginBtn.setBounds(pX,pY, btnWidth, btnHeight);
loginBtn.setOpaque(false);
loginBtn.setContentAreaFilled(false);
loginBtn.setBorderPainted(true);
loginBtn.setBorder(new RoundedBorder(20, "LOGOUT", true, Color.cyan, btnFont));
loginBtn.setForeground(Color.black);
panel.add(loginBtn);
loginBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
moveToLogin(dashboardFrame);
}
});
JSeparator bottomBorder = new JSeparator();
bottomBorder.setBackground(Color.black);
bottomBorder.setBounds(0, height-3, width, 2);
panel.add(bottomBorder);
return panel;
}
Here is simple RondedBorder Class.
public class RoundedBorder implements Border {
private int radius;
private String label;
private Boolean isFill;
private Color color;
private Font font;
public RoundedBorder(int radius, String label, Boolean isFill, Color color, Font font) {
this.radius = radius;
this.label = label;
this.isFill = isFill;
this.color = color;
this.font = font;
}
public boolean isBorderOpaque() {
return false;
}
@Override
public Insets getBorderInsets(Component arg0) {
// TODO Auto-generated method stub
return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
// TODO Auto-generated method stub
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(color);
RoundRectangle2D round=new RoundRectangle2D.Double(x, y, width-1, height-1, radius, radius);
if(!isFill) {
g2.setStroke(new BasicStroke((float) 1));
g2.draw(round);
} else {
g2.fill(round);
}
if(label != "") {
g2.setFont(font);
FontMetrics fm = g2.getFontMetrics();
g2.setColor(Color.BLACK);
int strW = fm.stringWidth(label);
g2.drawString(label, width/2 - strW/2, height/2 + fm.getAscent()/2);
}
}
}
Now we Create WElcome ,Question and Result Layouts.
int logoutBarWidth = panelWidth*94/100;
int logoutBarHeight = panelHeight*75/100;
posX = (int) (panelWidth*3/100 - 1);
posY = (int) (panelHeight * 21 /100);
font = new Font("Lucida", Font.PLAIN, 48);
welcome_panel = createWelcomePanel(logoutBarWidth, logoutBarHeight, posX,posY, "", false, Color.black, font);
panel.add(welcome_panel);
welcome_panel.setLayout(null);
welcome_panel.setVisible(true);
quiz_panel = createQuizPanel(logoutBarWidth, logoutBarHeight, posX,posY, "", false, Color.black, font);
panel.add(quiz_panel);
quiz_panel.setLayout(null);
quiz_panel.setVisible(false);
result_panel = createResultPanel(logoutBarWidth, logoutBarHeight, posX,posY, "", false, Color.black, font);
panel.add(result_panel);
result_panel.setLayout(null);
result_panel.setVisible(false);
Here is Welcome UI with "START QUIZ" Button .
private JPanel createWelcomePanel(int width, int height,int posX, int posY, String titelName, boolean isFill, Color color, Font font) {
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setEnabled(true);
panel.setSize(new Dimension(width, height));
panel.setLocation(posX, posY);
panel.setBorder(new RoundedBorder(10, titelName, isFill, color, font));
// Welcome Layout
int pY = height * 10/100;
Font font1 = new Font("Lucida", Font.PLAIN, 48);
JLabel welcome_lbl = new JLabel();
welcome_lbl.setText("WELCOME");
welcome_lbl.setFont(font1);
welcome_lbl.setForeground(Color.green);
welcome_lbl.setSize(new Dimension(width, height / 9));
welcome_lbl.setHorizontalAlignment(JLabel.CENTER);
welcome_lbl.setLocation(0, pY);
panel.add(welcome_lbl);
pY = height * 30/100;
font1 = new Font("Lucida", Font.PLAIN, 20);
JLabel welcome_TXT_lbl = new JLabel();
welcome_TXT_lbl.setText("Happy to have you..!!");
welcome_TXT_lbl.setFont(font1);
welcome_TXT_lbl.setForeground(Color.blue);
welcome_TXT_lbl.setSize(new Dimension(width, height / 9));
welcome_TXT_lbl.setHorizontalAlignment(JLabel.CENTER);
welcome_TXT_lbl.setLocation(0, pY);
panel.add(welcome_TXT_lbl);
int btnWidth = width *26/100;
int btnHeight = height *12/100;
int pX = width /2 - btnWidth/2;
pY = height *65/100;
font1 = new Font("Lucida", Font.PLAIN, 18);
JButton start_Quiz_Btn = new JButton();
start_Quiz_Btn.setBounds(pX,pY, btnWidth, btnHeight);
start_Quiz_Btn.setOpaque(false);
start_Quiz_Btn.setContentAreaFilled(false);
start_Quiz_Btn.setBorderPainted(true);
start_Quiz_Btn.setBorder(new RoundedBorder(55, "START QUIZ", true, Color.cyan, font1));
start_Quiz_Btn.setForeground(Color.black);
panel.add(start_Quiz_Btn);
start_Quiz_Btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
startQuizBtnClick();
}
});
return panel;
}
Here is Quiz UI and Create "NEXT" , "PRIVIOUS" , "SUBMIT" Button with logic to need to appear .
private JPanel createQuizPanel(int width, int height,int posX, int posY, String titelName, boolean isFill, Color color, Font font) {
try {
String projectPath = System.getProperty("user.dir");
String replaceString;
String excelFilePath;
if (isWindows()) {
replaceString = projectPath.replace("\\", "\\\\");
excelFilePath = replaceString+ "\\text1.xlsx";
} else if (isMac()) {
replaceString = projectPath.replace("\\", "//");
excelFilePath = replaceString+ "//text1.xlsx";
} else if (isUnix()) {
replaceString = projectPath.replace("\\", "//");
excelFilePath = replaceString+ "//text1.xlsx";
} else {
//System.out.println("Your OS is not support!!");
replaceString = projectPath.replace("\\", "\\\\");
excelFilePath = replaceString+ "\\text1.xlsx";
}
FileInputStream fis=new FileInputStream(excelFilePath);
wb=new XSSFWorkbook(fis);
}
catch(FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e1) {
e1.printStackTrace();
}
resultMap = new HashMap();
JPanel base_panel = new JPanel();
base_panel.setOpaque(false);
base_panel.setEnabled(true);
base_panel.setSize(new Dimension(width, height));
base_panel.setLocation(posX, posY);
base_panel.setLayout(null);
int h = height * 82 / 100;
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setEnabled(true);
panel.setSize(new Dimension(width, h));
panel.setLocation(0, 0);
panel.setBorder(new RoundedBorder(20, titelName, isFill, color, font));
panel.setLayout(null);
base_panel.add(panel);
// time Layout
int labelWidth = width * 20 / 100;
h = height * 7 / 100;
int pX = width - width*20/100;
int pY = height * 2/100;
Font font1 = new Font("Lucida", Font.PLAIN, 25);
timer_lbl = new JLabel();
timer_lbl.setText("Time: 00:00");
timer_lbl.setFont(font1);
timer_lbl.setForeground(Color.black);
timer_lbl.setSize(new Dimension(labelWidth, h));
timer_lbl.setHorizontalAlignment(JLabel.CENTER);
timer_lbl.setLocation(pX, pY);
panel.add(timer_lbl);
// Question No Layout
labelWidth = width * 96 / 100;
pX = width*2/100;
pY = height * 10/100;
font1 = new Font("Lucida", Font.PLAIN, 30);
question_NO_lbl = new JLabel();
question_NO_lbl.setText("Question No: ");
question_NO_lbl.setFont(font1);
question_NO_lbl.setForeground(Color.black);
question_NO_lbl.setSize(new Dimension(labelWidth, h));
//question_NO_lbl.setHorizontalAlignment(JLabel.CENTER);
question_NO_lbl.setLocation(pX, pY);
panel.add(question_NO_lbl);
// Question DATA Layout
pX = width*2/100;
pY = height * 19/100;
h = height * 20 / 100;
font1 = new Font("Lucida", Font.PLAIN, 18);
question_DATA_lbl = new JTextArea();
question_DATA_lbl.setEditable(false);
question_DATA_lbl.setCursor(null);
question_DATA_lbl.setOpaque(false);
question_DATA_lbl.setFocusable(false);
question_DATA_lbl.setLineWrap(true);
question_DATA_lbl.setWrapStyleWord(true);
question_DATA_lbl.setText("Question No: ");
question_DATA_lbl.setFont(font1);
question_DATA_lbl.setForeground(Color.black);
question_DATA_lbl.setSize(new Dimension(labelWidth, h));
question_DATA_lbl.setLocation(pX, pY);
panel.add(question_DATA_lbl);
//Radio Button
int optionWidth = width * 96/100;
int optionHeight = height * 6/100;
pY = height * 50/100;
option1=new JRadioButton();
option1.setText("A");
option1.setBounds(pX,pY, optionWidth, optionHeight);
panel.add(option1);
pY = height * 57/100;
option2 =new JRadioButton();
option2.setBounds(pX,pY, optionWidth, optionHeight);
panel.add(option2);
pY = height * 64/100;
option3 =new JRadioButton();
option3.setBounds(pX,pY, optionWidth, optionHeight);
panel.add(option3);
pY = height * 71/100;
option4 =new JRadioButton();
option4.setBounds(pX,pY, optionWidth, optionHeight);
panel.add(option4);
bg = new ButtonGroup();
bg.add(option1);
bg.add(option2);
bg.add(option3);
bg.add(option4);
option1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (option1.isSelected()) {
//System.out.println(ReadCellData(wb, currentQuestionNo, 6 ) + "------A");
String queNo = "Que"+ currentQuestionNo;
String[] resultStr = new String[]{ReadCellData(wb, currentQuestionNo, 6 ), "A"};
if (resultMap.containsKey(queNo)) {
resultMap.replace(queNo, resultStr);
} else {
resultMap.put(queNo,resultStr);
}
}
}
});
option2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (option2.isSelected()) {
//System.out.println(ReadCellData(wb, currentQuestionNo, 6 ) + "------B");
String queNo = "Que"+ currentQuestionNo;
String[] resultStr = new String[]{ReadCellData(wb, currentQuestionNo, 6 ), "B"};
if (resultMap.containsKey(queNo)) {
resultMap.replace(queNo, resultStr);
} else {
resultMap.put(queNo,resultStr);
}
}
}
});
option3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (option3.isSelected()) {
//System.out.println(ReadCellData(wb, currentQuestionNo, 6 ) + "------C");
String queNo = "Que"+ currentQuestionNo;
String[] resultStr = new String[]{ReadCellData(wb, currentQuestionNo, 6 ), "C"};
if (resultMap.containsKey(queNo)) {
resultMap.replace(queNo, resultStr);
} else {
resultMap.put(queNo,resultStr);
}
}
}
});
option4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (option4.isSelected()) {
//System.out.println(ReadCellData(wb, currentQuestionNo, 6 ) + "------D");
String queNo = "Que"+ currentQuestionNo;
String[] resultStr = new String[]{ReadCellData(wb, currentQuestionNo, 6 ), "D"};
if (resultMap.containsKey(queNo)) {
resultMap.replace(queNo, resultStr);
} else {
resultMap.put(queNo,resultStr);
}
}
}
});
//PREVIOUS BUTTON
int btnWidth = width *22/100;
int btnHeight = height *10/100;
pX = width*2/100;
pY = height *85/100;
font1 = new Font("Lucida", Font.PLAIN, 18);
previous_Btn = new JButton();
previous_Btn.setBounds(pX, pY, btnWidth, btnHeight);
previous_Btn.setOpaque(false);
previous_Btn.setContentAreaFilled(false);
previous_Btn.setBorderPainted(true);
previous_Btn.setBorder(new RoundedBorder(55, "PREVIOUS", true, Color.cyan, font1));
previous_Btn.setForeground(Color.black);
base_panel.add(previous_Btn);
previous_Btn.setVisible(false);
previous_Btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
previousBtnClick();
}
});
//NEXT BUTTON
pX = width - btnWidth - width*2/100;;
next_Btn = new JButton();
next_Btn.setBounds(pX,pY, btnWidth, btnHeight);
next_Btn.setOpaque(false);
next_Btn.setContentAreaFilled(false);
next_Btn.setBorderPainted(true);
next_Btn.setBorder(new RoundedBorder(55, "NEXT", true, Color.cyan, font1));
next_Btn.setForeground(Color.black);
base_panel.add(next_Btn);
next_Btn.setVisible(true);
next_Btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
nextBtnClick();
}
});
//SUBMIT BUTTON
submit_Btn = new JButton();
submit_Btn.setBounds(pX,pY, btnWidth, btnHeight);
submit_Btn.setOpaque(false);
submit_Btn.setContentAreaFilled(false);
submit_Btn.setBorderPainted(true);
submit_Btn.setBorder(new RoundedBorder(55, "SUBMIT", true, Color.cyan, font1));
submit_Btn.setForeground(Color.black);
base_panel.add(submit_Btn);
submit_Btn.setVisible(false);
submit_Btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
submitBtnClick();
}
});
currentQuestionNo = 0;
nextBtnClick();
return base_panel;
}
private JPanel createResultPanel(int width, int height,int posX, int posY, String titelName, boolean isFill, Color color, Font font) {
String key= "";
for (int i=0; i<10; i++) {
key = "Que"+ (i+1);
}
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setEnabled(true);
panel.setSize(new Dimension(width, height));
panel.setLocation(posX, posY);
panel.setBorder(new RoundedBorder(10, titelName, isFill, color, font));
// result head Layout
int pY = height * 15/100;
Font font1 = new Font("Lucida", Font.PLAIN, 48);
JLabel result_HEAD_lbl = new JLabel();
result_HEAD_lbl.setText("REPORT CARD");
result_HEAD_lbl.setFont(font1);
result_HEAD_lbl.setForeground(Color.red);
result_HEAD_lbl.setSize(new Dimension(width, height / 9));
result_HEAD_lbl.setHorizontalAlignment(JLabel.CENTER);
result_HEAD_lbl.setLocation(0, pY);
panel.add(result_HEAD_lbl);
// result Layout
pY = height * 35/100;
font1 = new Font("Lucida", Font.PLAIN, 20);
result_TXT_lbl = new JLabel();
result_TXT_lbl.setText("");
result_TXT_lbl.setFont(font1);
result_TXT_lbl.setForeground(Color.green);
result_TXT_lbl.setSize(new Dimension(width, height / 9));
result_TXT_lbl.setHorizontalAlignment(JLabel.CENTER);
result_TXT_lbl.setLocation(0, pY);
panel.add(result_TXT_lbl);
// result description Layout
pY = height * 48/100;
font1 = new Font("Lucida", Font.PLAIN, 20);
result_DESC_lbl = new JLabel();
result_DESC_lbl.setText("");
result_DESC_lbl.setFont(font1);
result_DESC_lbl.setForeground(Color.magenta);
result_DESC_lbl.setSize(new Dimension(width, height / 9));
result_DESC_lbl.setHorizontalAlignment(JLabel.CENTER);
result_DESC_lbl.setLocation(0, pY);
panel.add(result_DESC_lbl);
return panel;
}
Now All UI Complete, Here's Configration to start quiz when click "Start Quiz" Button.
private void startQuizBtnClick() {
welcome_panel.setVisible(false);
quiz_panel.setVisible(true);
long start = System.currentTimeMillis();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
long end = System.currentTimeMillis();
long elapsedTime = (end - start)/1000;
int sec;
// converting it into minutes
int minutes=((int) (elapsedTime))/60;
if (minutes >= 30) {
String key= "";
int total = 0;
for (int i=0; i<10; i++) {
key = "Que"+ (i+1);
if(resultMap.containsKey(key)) {
String givenAns = resultMap.get(key)[1];
String CurrecAns = resultMap.get(key)[0];
if (givenAns.equalsIgnoreCase(CurrecAns)) {
total = total + 10;
}
}
}
String str = "";
if (total <= 50) {
str = "Hard Luck..!! Try next time";
} else if (total == 100) {
str = "Excellent..!!";
} else if (total > 50 && total < 100 ) {
str = "Try Harder..!!";
}
result_TXT_lbl.setText("Marks obtained "+total+" out of 100");
result_DESC_lbl.setText(str);
quiz_panel.setVisible(false);
result_panel.setVisible(true);
} else {
// converting it into minutes
sec= ((int) (elapsedTime))%60;
timer_lbl.setText("Time: "+ new DecimalFormat("00").format(minutes)+":"+new DecimalFormat("00").format(sec));
}
}
}, 1000, 1000);
}
Here is logic to go privious question when click "PRIVIOUS" Button.
private void previousBtnClick() {
currentQuestionNo = currentQuestionNo - 1;
question_NO_lbl.setText( "Question No :- " + currentQuestionNo);
question_DATA_lbl.setText("Question:- " + ReadCellData(wb, currentQuestionNo, 1 ));
option1.setText("A. " + ReadCellData(wb, currentQuestionNo, 2 ));
option2.setText("B. " + ReadCellData(wb, currentQuestionNo, 3 ));
option3.setText("C. " + ReadCellData(wb, currentQuestionNo, 4 ));
option4.setText("D. " + ReadCellData(wb, currentQuestionNo, 5 ));
if(currentQuestionNo == 1) {
previous_Btn.setVisible(false);
} else if (currentQuestionNo == 9) {
submit_Btn.setVisible(false);
next_Btn.setVisible(true);
}
String key = "Que"+ currentQuestionNo;
String currectAns = "";
if (resultMap.containsKey(key)) {
currectAns = resultMap.get(key)[1];
if(currectAns =="A") {
option1.setSelected(true);
} else if(currectAns =="B") {
option2.setSelected(true);
} else if(currectAns =="C") {
option3.setSelected(true);
} else if(currectAns =="D") {
option4.setSelected(true);
}
} else {
bg.clearSelection();
}
}
Here is logic for next question when click "NEXT" Button.
private void nextBtnClick() {
currentQuestionNo = currentQuestionNo + 1;
question_NO_lbl.setText( "Question No :- " + currentQuestionNo);
question_DATA_lbl.setText("Question:- " + ReadCellData(wb, currentQuestionNo, 1 ));
option1.setText("A. " + ReadCellData(wb, currentQuestionNo, 2 ));
option2.setText("B. " + ReadCellData(wb, currentQuestionNo, 3 ));
option3.setText("C. " + ReadCellData(wb, currentQuestionNo, 4 ));
option4.setText("D. " + ReadCellData(wb, currentQuestionNo, 5 ));
if(currentQuestionNo == 10) {
next_Btn.setVisible(false);
submit_Btn.setVisible(true);
} else if(currentQuestionNo == 2) {
previous_Btn.setVisible(true);
} else if(currentQuestionNo == 1) {
previous_Btn.setVisible(false);
}
String key = "Que"+ currentQuestionNo;
String currectAns = "";
if (resultMap.containsKey(key)) {
currectAns = resultMap.get(key)[1];
if(currectAns =="A") {
option1.setSelected(true);
} else if(currectAns =="B") {
option2.setSelected(true);
} else if(currectAns =="C") {
option3.setSelected(true);
} else if(currectAns =="D") {
option4.setSelected(true);
}
} else {
bg.clearSelection();
}
}
Here Is logic of prompat confirmation message and submit quiz when click "SUBMIT" Button.
private void submitBtnClick() {
int result = JOptionPane.showConfirmDialog(dashboardFrame, "Sure? Do you really want to submit?",
"Submit", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(result == JOptionPane.YES_OPTION){
String key= "";
int total = 0;
for (int i=0; i<10; i++) {
key = "Que"+ (i+1);
if(resultMap.containsKey(key)) {
String givenAns = resultMap.get(key)[1];
String CurrecAns = resultMap.get(key)[0];
if (givenAns.equalsIgnoreCase(CurrecAns)) {
total = total + 10;
}
}
}
String str = "";
if (total <= 50) {
str = "Hard Luck..!! Try next time";
} else if (total == 100) {
str = "Excellent..!!";
} else if (total > 50 && total < 100 ) {
str = "Try Harder..!!";
}
result_TXT_lbl.setText("Marks obtained "+total+" out of 100");
result_DESC_lbl.setText(str);
quiz_panel.setVisible(false);
result_panel.setVisible(true);
}
Here is logic for read data from xlsx file.
public String ReadCellData(Workbook wb, int vRow, int vColumn) {
String value=null; //variable for storing the cell value
Sheet sheet=wb.getSheetAt(0); //getting the XSSFSheet object at given index
Row row=sheet.getRow(vRow); //returns the logical row
Cell cell=row.getCell(vColumn); //getting the cell representing the given column
value=cell.getStringCellValue(); //getting cell value
return value; //returns the cell value
}
Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.
Copyright 2021 by Programmer Mitra. All Rights Reserved.