In my application I am extracting data from a project DB. When I do that I want to signal to user that data extraction is in progress. I want to achieve this by making my current frame view.getFrame2()
invisible and making view.getFrame3()
visible. Frame 3 will have GIF image with frame titled as "Extraction is in progress". I am able to achieve my target but I am not able to view the image in the frame. It's blank.
Below is the code snippet I am using; one class is used for view, another one for controller and yet another one for the model. I also have a main class to initialize all the M-V-C classes. I don't want to complicate the code by creating more classes.
View
My View class:-
/** View**/
package mvc.views;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import javax.swing.*;
public class View {
JFrame frame2, frame3;
JPanel panel3;
Toolkit tk;
Image icon;
Color background;
public View() {
/** processing image view **/
frame3 =new JFrame();
frame3.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame3.setTitle( "Extraction in process...." );
try {
icon = new ImageIcon("C:\\Users\\pc033k\\Desktop\\gears_animated.gif").getImage();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
panel3 = new JPanel();
background = Color.white;
panel3.setOpaque(true);
frame3.setContentPane(panel3);;
frame3.setBounds(100, 100, 400, 400);
frame3.setLocationRelativeTo(null);
frame3.setVisible(false);
/** End of processing image view **/
}
public void paint (Graphics g)
{
panel3.paint(g);
panel3.setBackground(background);
g.drawImage(icon,100,100,500,500,null);
}
}
/** End of View**/
Controller
/** Start Controller**/
package mvc.controllers;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import mvc.models.*;
import mvc.views.*;
public class Controller {
public Model model;
public View view;
public ActionListener myButtonListener;
//public MyDateListener listener;
boolean status, process1;
public String user, password, FN, LN, type;
JTextField text1, text2;
JCalendarCombo cal1, cal2;
public Date date1, date2;
public Controller(Model model, View view) {
this.model = model;
this.view = view;
}
public class MyButtonListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == view.getGetcrmdataButton()){
FN = view.getUserText1().getText();
LN = view.getUserText2().getText();
date1 = view.getCalendar2().getDate();
date2 = view.getCalendar3().getDate();
type = (String) view.getComb1().getSelectedItem();
view.getFrame2().dispose();
view.getFrame3().setVisible(true);
view.getFrame3().repaint();
try {
process1 = model.CRMDataExtract(FN, LN, date1, date2, type);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(process1 == true){
view.getFrame3().setVisible(false);
view.getFrame2().setVisible(true);
JOptionPane.showMessageDialog((Component) (e.getSource()),
"pealse Check the output file for the data");
}
else
{
view.getFrame3().setVisible(false);
view.getFrame2().setVisible(true);
JOptionPane.showMessageDialog((Component) (e.getSource()),
" No Records found or Data Extraction failed!!");
}
}
}
}