Wednesday 8 January 2014

Calender 2014 Developed on Java Swing......

import javax.swing.*;
import javax.swing.event.*;
import java.awt.Color;
import java.awt.*;
import java.awt.event.*;

class calen extends JFrame implements ItemListener,ActionListener
{
int i=0;
int j=0;
int k=0;
int m=0;
JFrame jf;
GridLayout gl;
JPanel jp[];
JPanel jpc;
JPanel jp1;
JPanel jp2;
JButton jb [];
JButton jb3[];
JLabel jlb[];
JButton jb1;
JButton jb2;
CardLayout cl;
JComboBox cb;
calen()
{
cl=new CardLayout();

jp1=new JPanel();
jpc=new JPanel();
Container content=getContentPane();
jp2=new JPanel();
jf=new JFrame ("HAPPY 2014 :-)");
gl=new GridLayout(7,5,0,0);
jb=new JButton[37];
jp=new JPanel[12];
jb1=new JButton("PREVIOUS");
jb2=new JButton("NEXT");
String days[]={"Sun", "Mon","Tue", "Wed", "Thurs", "Fri", "Sat"};
String months[]={"Jan", "Feb","March", "Apr", "May", "June","July", "August","September","October","November","December"};
cb=new JComboBox(months);
cb.setEditable(false);
cb.addItemListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3=new JButton[7];
String dates[][]={{" "," "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"," "," "," "},{" "," "," "," "," "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28"," "," "," "},{" "," "," "," "," "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"},{" "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30"," "," "," "," "," "},{" "," "," "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"," "," "},{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30"," "," "," "," "," "," "," "},{" "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"," "," "," "," "},{" "," "," "," "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"," "},{" ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30"," "," "," "," "," "," "},{" "," "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"," "," "," "},{" "," "," "," "," "," ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30"," "},{" ","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30","31"," "," "," "," "," "}};
Color colors[]={Color.yellow, Color.yellow, Color.pink, Color.red, Color.orange, Color.white, Color.blue, Color.green, Color.pink,
Color.magenta, Color.darkGray,Color.cyan};
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(720,450);
jlb=new JLabel[12];
jp1=new JPanel();
jp2=new JPanel();
jp1.setLayout(cl);
jpc.setLayout(cl);
for( i=0; i<months.length; i++)
{
jp[i]=new JPanel();
jlb[i]=new JLabel(months[i]);
jlb[i].setFont(new Font("Serif",Font.PLAIN,30));
jlb[i].setBackground(colors[i]);
jlb[i].setOpaque(true);
jp1.add(jlb[i]);
jp2.add(cb);

 

for(j=0; j<days.length; j++)
{
jb3[j]=new JButton(days[j]);
jp[i].add(jb3[j]);
}
for(k=0; k<37; k++)
{
try
{
jb[k]=new JButton(dates[i][k]);
jp[i].add(jb[k]);
}
catch(Exception e)
{
System.out.println("exception");
}
}
jp[i].setLayout(gl);
jp[i].setBackground(colors[i]);
jp1.setBackground(colors[i]);
jp2.add(jb1);
jp2.add(jb2);
jpc.add(jp[i]);
jp1.setLayout(cl);
add(jp1);
add(jp2);
add(jpc);
content.add(jp1, BorderLayout.NORTH);
content.add(jp2, BorderLayout.SOUTH);
//content.add(jp[i]);
content.add(jpc);

setVisible(true);
}
}
public void itemStateChanged(ItemEvent e)
{
cl.show(jpc, (String)e.getItem());
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource()==jb1)
{
cl.previous(jpc);
cl.previous(jp1);
}
else
{
cl.next(jpc);
cl.next(jp1);
}
}
public static void main(String...s)
{
new calen();
}
}

  

Wednesday 28 August 2013

How to make a table cell be edited on KeyPressed in JavaFx2.2



public void startEdit() {
super.startEdit();
createTextField();
setText(null);
setGraphic(textField);

/**
* put focus on the textfield so user can directly typed on it
*/
Runnable r = new Runnable() {
@Override
public void run() {
getGraphic().requestFocus();
}
};
Platform.runLater(r);

}

How to insert dynamic Image Path in Mysql using Javafxml

Hiii Here i have taken two text Field and one ImageView .now i have taken dynamic image from Filechooser and then store it into MySql database.




 s1=t1.getText();
             s2=t2.getText();
             s3=l1.getText();
            // img1.getProperties();
           
        {
            try{

            Class.forName("com.mysql.jdbc.Driver").newInstance();

        }catch(ClassNotFoundException cnfe){

            System.err.println("Error: "+cnfe.getMessage());

        }catch(InstantiationException ie){

            System.err.println("Error: "+ie.getMessage());

        }catch(IllegalAccessException iae){

            System.err.println("Error: "+iae.getMessage());

        }
           try
           {
            Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/farhan","root","root" );
              String query="insert into Product_Detail(Prod_No,Prod_Name,Picture)values(?,?,?)";
         
           System.out.println("hiiiiiii man54");
           PreparedStatement ps=conn.prepareStatement(query);
           System.out.println("hiiiiiii man32");
           ps.setString(1,s1);
        ps.setString(2, s2);
        ps.setString(3,s3);
       int i = ps.executeUpdate();
         
           }
           catch(Exception e)
           {
             
                 e.printStackTrace();
           }
         
           System.out.println("database");
           if(i==1)
           {
               System.out.println("database count 1");
             
               System.out.println("Successfully inserted");
           }
           else
           {
               System.out.println("Incorrect Syntac");
           }

Monday 26 August 2013

How to Load dynamic image in JavaFx

Use Filechooser for the dialog box and specify the extension which u want to take and load it on to your requirement.      

  FileChooser fileChooser = new FileChooser();
         
          System.out.print("in browse button handle action event,mouse clicked");
            FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
           FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
           fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG);
             File file = fileChooser.showOpenDialog(null);
         
           
                BufferedImage bufferedImage = ImageIO.read(file);
                WritableImage image = SwingFXUtils.toFXImage(bufferedImage,null);
                 img1.setImage(image);

javafx.stage.Popup as JOptionPane

It is easy to create JoptionPane equivalent in Javafx2.0.
Here is a custom Component:

import javafx.stage.*; 
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.control.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;

public class ModalDialog {
    Button Button b1,b2;
    public ModalDialog(final Stage stg) {

            final Stage dialog = new Stage();
            dialog.setTitle("Confirm Before Exit");
            dialog.setResizable(false);
          // dialog.initOwner(Demoslide.getPrimaryStage());
            dialog.initModality(Modality.APPLICATION_MODAL);

            FlowPane buttons = new FlowPane(10,10);
            buttons.setAlignment(Pos.CENTER);
            Button yes = new Button("Yes");
           Button no = new Button("No");
            buttons.getChildren().addAll(yes, no);
            VBox box = new VBox();
            box.setAlignment(Pos.CENTER);
            box.setSpacing(10);
            box.getChildren().addAll(new Label("Successfully login "), buttons);
             Scene s = new Scene(box);
            dialog.setScene(s);
            dialog.show();
         }
      
      
    }

How to popup message below Taskbar right-corner



// when message is received
JDialog d = new JDialog();
d.setSize(200,200);
d.setLocation(theXLocation, theYLocation);
d.add(new JLabel(message);
d.setVisible(true);
where the x and y location match the right corner

to get these locations, see the toolkit class, that will allow you to get the dimension of the screen