void ctrlSetup()
{
tk=getToolkit();
//ta1=new JTextArea(800,600);
ta1=new JEditorPane();
sp1=new JScrollPane();
sp1.setViewportView(ta1);
// Box box=Box.createVerticalBox();
ta1.setBackground(Color.white);
//ta2=new JTextArea(800,600);
ta2=new JEditorPane();
sp2=new JScrollPane();
sp2.setViewportView(ta2);
ta2.setBackground(Color.white);
sp1.setBounds(5,43,790,360);
sp2.setBounds(5,425,790,145);
ta2.setEditable(false);
ta1.setEditable(true);
add(sp1);
add(sp2);
//add(box);
}
void menuSetup()
{
//System.out.println(" hi");
try{
final JFrame obj=this;
JMenuBar mb=new JMenuBar();
//JMenu Bars
JMenu m1=new JMenu("File");
m1.setMnemonic('F');
JMenu m2=new JMenu("Edit");
m2.setMnemonic('E');
JMenu m3=new JMenu("Search");
m3.setMnemonic('S');
JMenu m4=new JMenu("Format");
m4.setMnemonic('m');
JMenu m5=new JMenu("Run");
m5.setMnemonic('R');
JMenu m6=new JMenu("Window");
m6.setMnemonic('W');
JMenu m7=new JMenu("Help");
m7.setMnemonic('H');
//JMenuItems under File JMenu
JMenuItem m11=new JMenuItem("New");
m11.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
ta1.setText("");
d1=new JDialog(obj,"New ... ",true);
d1.setLocation(300,300);
d1.setSize(250,130);
d1.setLayout(new FlowLayout());
d1.add(new JLabel("Select the File Type"));
c=new JComboBox();
c.addItem("Application");
c.addItem("Applet");
c.addItem("Frame");
c.addItem("Swing");
c.addItem("JDBC");
c.addItem("Servlet");
c.addItem("JSP");
c.addItem("HTML");
d1.add(c);
JButton b1=new JButton("Start");
JButton b2=new JButton("Cancel");
d1.add(b1);
d1.add(b2);
//Configuring the Listener for Button on the Dialog Box
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent v)
{
String xx=(String)c.getSelectedItem();
String title=getTitle().substring(11,getTitle().length()-5);
if(xx=="Application")
{
String s1="import java.lang.*;";
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
s1+="\nclass " + title;
s1+="\n{\n\tpublic static void main(String args[])";
s1+="\n\t{\n\n\n\t}\n}";
ta1.setText(s1);
}
}
if(xx=="Frame")
{
String s1="import java.awt.*;";
s1+="\nimport java.awt.event.*;";
s1+="\nclass frame1 extends Frame";
s1+="\n{\n\tpublic frame1()\n\t{";
s1+="\n\tsuper(\"My Frame\");";
s1+="\n\tsetSize(300,300);";
s1+="\n\tsetLayout(new FlowLayout());";
s1+="\n\taddWindowListener(new WindowAdapter()";
s1+="\n\t{\n\tpublic void windowClosing(WindowEvent we){";
s1+="\n\tSystem.exit(0);";
s1+="\n\n\t}});";
s1+="\n\tsetVisible(true);\n\t}\n}";
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
s1+="\nclass " + title;
s1+="\n{\n\tpublic static void main(String args[])";
s1+="\n\t{\n\tnew frame1();\n\t}\n}";
ta1.setText(s1);
}
}
if(xx=="Applet")
{
String s1="import java.awt.*;";
s1+="\nimport java.awt.event.*;";
s1+="\nimport java.applet.*;";
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
s1+="\n//<applet code "+title+".class";
s1+="\npublic class " + title + " extends Applet";
s1+="\n{\n\tpublic void init()\n\t{\n\n\n\t}";
s1+="\n\tpublic void start()\n\t{\n\n\n\t}";
s1+="\n\tpublic void paint(Graphics g)\n\t{\n\n\n\t}";
s1+="\n\tpublic void stop()\n\t{\n\n\n\t}";
s1+="\n\tpublic void destroy()\n\t{\n\n\n\t}\n}";
ta1.setText(s1);
}
}
if(xx=="Swing")
{
String s1="import java.awt.*;";
s1+="\nimport java.awt.event.*;";
s1+="\nimport javax.swing.*;";
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
s1+="\n//<applet code "+title+".class";
s1+="\npublic class " + title + " extends JApplet";
s1+="\n{\n\tpublic void init()\n\t{\n\n\n\t";
s1+="\tContainer con=getContentPane();";
s1+="\n\n\tcon.add()\n\n\t}";
s1+="\n}";
ta1.setText(s1);
}
}
if(xx=="JDBC")
{
String s1="import java.sql.*;";
s1+="\nimport java.io.*;";
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
s1+="\npublic class " + title;
s1+="\n{\n\tpublic static void main(String ar[]) throws
Exception";
s1+="\n\t{\n\tClass.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\");";
s1+="\n\tConnection
cn=DriverManager.getConnection(\"jdbc:odbc:dsnname\");";
s1+="\n\tStatement
st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);";
s1+="\n\tResultSet rs=st.executeQuery(\"select * from tablename
\");";
s1+="\n\n\n\t}\n}";
ta1.setText(s1);
}
}
if(xx=="Servlet")
{
String s1="import javax.servlet.*;";
s1+="\nimport javax.servlet.http.*;";
s1+="\nimport java.io.*;\n";
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
s1+="\npublic class " + title + " extends HttpServlet";
s1+="\n{\n\tpublic void
doGet(HttpServeltRequestreq,HttpServletResponse res) throws
ServletException,IOException";
s1+="\n\t{\n\n\n\t}\n}";
ta1.setText(s1);
}
}
if(xx=="Jsp")
{
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
String s1="<html>";
s1+="\n<body>";
s1+="\n<%";
s1+="\n\n\n\n";
s1+="%>";
s1+="\n</body>";
s1+="\n</html>";
ta1.setText(s1);
}
}
if(xx=="HTML")
{
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile() + ".java");
title=getTitle().substring(11,getTitle().length()-5);
String s1="<html>";
s1+="\n<head>";
s1+="\n<title> Web page </title>";
s1+="\n</head>";
s1+="\n<body>";
s1+="\n\n\n\n";
s1+="\n</body>";
s1+="\n</html>";
ta1.setText(s1);
}
}
ta1.requestFocus();
d1.dispose();
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent v)
{
d1.dispose();
}
});
d1.setVisible(true);
}
});
JMenuItem m14=new JMenuItem("Open");
m14.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showOpenDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
setTitle("Pouwa 1.0 - " + fd.getSelectedFile());
try{
FileInputStream ds=new FileInputStream(fd.getSelectedFile());
int c;
ta1.setText("");
String sx="";
while((c=ds.read())!=-1)
sx=sx+(char)c;
ta1.setText(sx);
}catch(Exception se){}
}
}
});
JMenuItem m12=new JMenuItem("Save");
m12.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String t=getTitle();
File ff;
if (t=="Pouwa 1.0 - Untitled")
{
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
ff=new File(fd.getSelectedFile()+" ");
try{
PrintWriter pw = new PrintWriter(new FileOutputStream(ff),true);
pw.println(ta1.getText());
}catch(Exception fe){};
setTitle("Pouwa 1.0 - " + ff);
}
}
else
{
ff=new File(t.substring(11,t.length()));
try{
PrintWriter pw = new PrintWriter(new FileOutputStream(ff),true);
pw.println(ta1.getText());
}catch(Exception fe){};
setTitle("Pouwa 1.0 - " + ff);
}
}
});
JMenuItem m13=new JMenuItem("Save As");
m13.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String t=getTitle();
File ff;
JFileChooser fd=new JFileChooser();
fd.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result=fd.showSaveDialog(new JFrame());
if(result!=JFileChooser.CANCEL_OPTION)
{
ff=new File(fd.getSelectedFile()+" ");
try{
PrintWriter pw = new PrintWriter(new FileOutputStream(ff),true);
pw.println(ta1.getText());
}catch(Exception fe){};
setTitle("Pouwa 1.0 - " + ff);
}
}
});
JMenuItem m15=new JMenuItem("Close");
m15.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
setTitle("Pouwa 1.0 - Untitled");
ta1.setText("");
ta1.requestFocus();
}
});
JMenuItem m16=new JMenuItem("Quit");
m16.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
//JMenuItems under Edit JMenu
JMenuItem m21=new JMenuItem("Undo");
m21.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
ta1.setText(cs);
}
});
JMenuItem m22=new JMenuItem("Cut");
m22.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String s1=ta1.getSelectedText();
String b=ta1.getText();
cs=ta1.getText();
b=ta1.getText().substring(0,ta1.getCaretPosition());
b=b
+ta1.getText().substring(ta1.getCaretPosition()+ta1.getSelectedText().length(),ta1.getText().length());
ta1.setText(b);
StringSelection ss=new StringSelection(s1);
Clipboard cl=tk.getSystemClipboard();
cl.setContents(ss,ss);
}
});
JMenuItem m23=new JMenuItem("Copy");
m23.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String s1=ta1.getSelectedText();
StringSelection ss=new StringSelection(s1);
Clipboard cl=tk.getSystemClipboard();
cl.setContents(ss,ss);
}
});
JMenuItem m24=new JMenuItem("Paste");
m24.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String dat="";
Clipboard cl=tk.getSystemClipboard();
Transferable con=cl.getContents(this);
try{
dat=(String) con.getTransferData(DataFlavor.stringFlavor);
}
catch(Exception ex){}
StringBuffer tt=new StringBuffer(ta1.getText());
tt.insert(ta1.getCaretPosition(),dat);
ta1.setText(tt.toString());
}
});
JMenuItem m25=new JMenuItem("Clear");
m25.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String s1=ta1.getSelectedText();
String b=ta1.getText();
cs =ta1.getText();
b=ta1.getText().substring(0,ta1.getCaretPosition());
b=b
+ta1.getText().substring(ta1.getCaretPosition()+ta1.getSelectedText().length(),ta1.getText().length());
ta1.setText(b);
}
});
JMenuItem m26=new JMenuItem("Select All");
m26.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
ta1.select(0,ta1.getText().length());
}
});
//JMenuItems under Search JMenu
JMenuItem m31=new JMenuItem("Find");
m31.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
d1=new JDialog(obj,"Find ... ",true);
d1.setLocation(300,300);
d1.setSize(350,90);
d1.setLayout(new FlowLayout());
d1.add(new JLabel("Enter the Text to Find"));
t3=new JTextField(10);
d1.add(t3);
JButton b1=new JButton("Find");
JButton b2=new JButton("Cancel");
d1.add(b1);
d1.add(b2);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent we)
{
sf=t3.getText();
String tst=ta1.getText();
int az=tst.indexOf(sf,sso);
ta1.select(az,az+sf.length());
sso=az+sf.length();
d1.dispose();
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent we)
{
d1.dispose();
}
});
d1.setVisible(true);
}
});
JMenuItem m32=new JMenuItem("Find Next");
m32.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
sf=t3.getText();
String tst=ta1.getText();
int len=ta1.getText().length();
int az=0;
if(sso<=len)
az=tst.indexOf(sf,sso);
else
sso=0;
ta1.select(az,az+sf.length());
sso=az+sf.length();
}
});
//JMenuItems under Format JMenu
JMenuItem m41=new JMenuItem("Font");
m41.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
d1=new JDialog(obj,"Fonts .... ",true);
d1.setLocation(250,200);
d1.setSize(300,100);
d1.setLayout(new FlowLayout());
c1=new JComboBox();
String FontList[];
GraphicsEnvironment
ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
FontList=ge.getAvailableFontFamilyNames();
for(int i=0;i<FontList.length;i++)
c1.addItem(FontList[i]);
d1.add(c1);
c2=new JComboBox();
for(int i=8;i<=60;i+=2)
c2.addItem(i+"");
d1.add(c2);
c3=new JComboBox();
c3.addItem("Normal");
c3.addItem("Bold");
c3.addItem("Italic");
c3.addItem("Both");
d1.add(c3);
JButton b1=new JButton("OK");
JButton b2=new JButton("Cancel");
d1.add(b1);
d1.add(b2);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
d1.dispose();
String s1=(String)c1.getSelectedItem();
int s2=Integer.parseInt((String)c2.getSelectedItem());
String s3=(String)c3.getSelectedItem();
String s4="";
if (s3=="Normal")
{
ta1.setFont(new Font(s1,Font.PLAIN,s2));
ta2.setFont(new Font(s1,Font.PLAIN,s2));
}
else if(s3=="Bold")
{
ta1.setFont(new Font(s1,Font.BOLD,s2));
ta2.setFont(new Font(s1,Font.BOLD,s2));
}
else if(s3=="Italic")
{
ta1.setFont(new Font(s1,Font.ITALIC,s2));
ta2.setFont(new Font(s1,Font.ITALIC,s2));
}
else if(s3=="Both")
{
ta1.setFont(new Font(s1,Font.ITALIC+Font.BOLD,s2));
ta2.setFont(new Font(s1,Font.ITALIC+Font.BOLD,s2));
}
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
d1.dispose();
}
});
d1.setVisible(true);
}
});
//JMenu under Format JMenu
JMenu m42=new JMenu("Colors");
//JMenu Items Under Color JMenu
JMenuItem m421=new JMenuItem("ForeColor");
m421.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
d1=new JDialog(obj,"Colors .... ",true);
d1.setLocation(200,250);
d1.setSize(280,280);
d1.setLayout(null);
s1=new JScrollBar(0,0,10,0,255);
s2=new JScrollBar(0,0,10,0,255);
s3=new JScrollBar(0,0,10,0,255);
JLabel l1=new JLabel("Red");
JLabel l2=new JLabel("Green");
JLabel l3=new JLabel("Blue");
t1=new JTextField(10);
t1.setFont(new Font("Impact",Font.BOLD,30));
t1.setText("Aa");
l1.setBounds(10,37,100,10);
s1.setBounds(10,50,150,25);
l2.setBounds(10,77,100,10);
s2.setBounds(10,90,150,25);
l3.setBounds(10,117,100,10);
s3.setBounds(10,130,150,25);
s1.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
r1=s1.getValue();
t1.setForeground(new Color(r1,g1,b1));
}
});
s2.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
g1=s2.getValue();
t1.setForeground(new Color(r1,g1,b1));
}
});
s3.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
b1=s3.getValue();
t1.setForeground(new Color(r1,g1,b1));
}
});
t1.setBounds(165,75,75,60);
t1.setEditable(false);
d1.add(l1);
d1.add(l2);
d1.add(l3);
d1.add(s1);
d1.add(s2);
d1.add(s3);
d1.add(t1);
JButton b11=new JButton("OK");
JButton b2=new JButton("Cancel");
b11.setBounds(70,190,60,35);
b2.setBounds(150,190,90,35);
d1.add(b11);
d1.add(b2);
b11.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ta1.setForeground(new Color(r1,g1,b1));
ta2.setForeground(new Color(r1,g1,b1));
d1.dispose();
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
d1.dispose();
}
});
s1.requestFocus();
d1.setVisible(true);
}
});
JMenuItem m422=new JMenuItem("BackColor");
m422.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
d1=new JDialog(obj,"Colors .... ",true);
d1.setLocation(200,250);
d1.setSize(280,280);
d1.setLayout(null);
s1=new JScrollBar(0,0,10,0,255);
s2=new JScrollBar(0,0,10,0,255);
s3=new JScrollBar(0,0,10,0,255);
JLabel l1=new JLabel("Red");
JLabel l2=new JLabel("Green");
JLabel l3=new JLabel("Blue");
t1=new JTextField(10);
t1.setText("Sample");
l1.setBounds(10,37,100,10);
s1.setBounds(10,50,150,25);
l2.setBounds(10,77,100,10);
s2.setBounds(10,90,150,25);
l3.setBounds(10,117,100,10);
s3.setBounds(10,130,150,25);
s1.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
r=s1.getValue();
t1.setBackground(new Color(r,g,b));
}
});
s2.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
g=s2.getValue();
t1.setBackground(new Color(r,g,b));
}
});
s3.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
b=s3.getValue();
t1.setBackground(new Color(r,g,b));
}
});
t1.setBounds(165,75,75,60);
t1.setEnabled(false);
d1.add(l1);
d1.add(l2);
d1.add(l3);
d1.add(s1);
d1.add(s2);
d1.add(s3);
d1.add(t1);
JButton b1=new JButton("OK");
JButton b2=new JButton("Cancel");
b1.setBounds(70,190,60,35);
b2.setBounds(150,190,90,35);
d1.add(b1);
d1.add(b2);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ta1.setBackground(new Color(r,g,b));
ta2.setBackground(new Color(r,g,b));
d1.dispose();
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
d1.dispose();
}
});
d1.setVisible(true);
}
});
//Adding JMenu Items to Colors JMenu
m42.add(m421);
m42.add(m422);
//JMenu Items Under Run JMenu
JMenuItem m51=new JMenuItem("Compile");
m51.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try{
String r = getTitle().substring(11,getTitle().length());
Runtime rt =Runtime.getRuntime();
Process p=rt.exec("javac "+r);
p.waitFor();
int i =p.exitValue();
InputStream ip =p.getErrorStream();
int a =ip.available();
ta2.setText("");
ta2.setText("Compiling ...." +"\n\n");
if(a==0)
ta2.setText(ta2.getText()+"Good !!. There is no error in your Program
\n");
else
{
int c;
String ts=ta2.getText();
while((c =ip.read()) != -1)
{
ts=ts+(char) c;
}
ta2.setText(ts);
}
}catch(Exception ex){}
}
});
JMenuItem m52=new JMenuItem("Application");
m52.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String r = getTitle().substring(11,getTitle().length()-5);
try
{
Runtime t =Runtime.getRuntime();
Process p=t.exec("java "+r);
//Process p=t.exec("pwd");
p.waitFor();
int i =p.exitValue();
InputStream ip =p.getErrorStream();
int a =ip.available();
ta2.setText("Output of " + r + ".java ...... \n\n");
String ts=ta2.getText();
//p.waitFor();
if(a!=0)
{
int c;
while((c =ip.read()) != -1)
{
ts=ts+(char) c;
}
ta2.setText(ts);
}
else
ta2.setText("Program Successfully Executed");
}catch(Exception eq){}
}
});
JMenuItem m53=new JMenuItem("Applet");
m53.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String r = getTitle().substring(11,getTitle().length());
try
{
Runtime t =Runtime.getRuntime();
Process p=t.exec("appletviewer "+r);
p.waitFor();
int i =p.exitValue();
InputStream ip =p.getInputStream();
int a =ip.available();
ta2.setText("Applet Executed");
String ts=ta2.getText();
int c;
while((c =ip.read()) != -1)
{
ts=ts+(char) c;
}
ta2.setText(ts);
}catch(Exception eq){}
}
});
JMenuItem m54=new JMenuItem("Servlet Runner");
m54.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String r = getTitle().substring(11,getTitle().length());
//String ah =r.getName();
String ah=r;
StringBuffer st1 = new StringBuffer(r);
String a =st1.toString();
String aa1 = a.replace('\\', '/');
StringTokenizer st=new StringTokenizer(aa1,".");
String s1=st.nextToken();
String result ="firefox http://localhost:7001/servlet/"+s1;
try
{
Process p=Runtime.getRuntime().exec(result);
}
catch(Exception ew)
{}
}
});
JMenuItem m541=new JMenuItem("Jsp Runner");
m541.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
String r = getTitle().substring(11,getTitle().length());
//String ah =r.getName();
String ah=r;
StringBuffer st1 = new StringBuffer(r);
String a =st1.toString();
String aa1 = a.replace('\\', '/');
StringTokenizer st=new StringTokenizer(aa1,".");
String s1=st.nextToken();
String result ="firefox http://localhost:8080/test/"+s1;
try
{
Process p=Runtime.getRuntime().exec(result);
}
catch(Exception ew)
{}
}
});
JMenuItem m55=new JMenuItem("Mozilla Firefox");
m55.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try{
String r =getTitle().substring(11,getTitle().length());
Runtime t =Runtime.getRuntime();
String result ="firefox"+r;
Process p=t.exec(result);
p.waitFor();
int i =p.exitValue();
}catch(Exception ip){}
}
});
JMenuItem m56=new JMenuItem("MySQL");
m56.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
new DisplayQueryResults();
}
});
//JMenu Items under Window JMenu
m61=new JCheckBoxMenuItem("Full Screen");
m62=new JCheckBoxMenuItem("Output Window",true);
//Adding Listeners to these Check JMenu Items
m61.addItemListener(this);
m62.addItemListener(this);
//JMenu Items to the Help JMenu
JMenuItem m71=new JMenuItem("Help");
m71.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try{
Runtime t =Runtime.getRuntime();
Process p=t.exec("firefox
http://java.sun.com/javase/6/docs/api/index.html");
p.waitFor();
int i =p.exitValue();
}catch(Exception ip){}
}
});
JMenuItem m72=new JMenuItem("About Pouwa 1.0");
m72.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
d1=new JDialog(obj,"About Pouwa 1.0",true);
d1.setLocation(100,100);
d1.setSize(400,550);
d1.setLayout(null);
JLabel l1=new JLabel("Pouwa 1.0");
JLabel l2=new JLabel("Red Hat/Ubuntu/Fedora/Debian/Suse/Solaris");
JLabel l3=new JLabel("Belongs to FOSS Community");
JLabel l4=new JLabel("By-Sirshak Das");
JLabel l5=new JLabel("Mentor:Debashish Pratihari");
JLabel l6=new JLabel("Dedicated to Pouwa");
JButton b1=new JButton("OK");
l1.setBounds(50,50,200,25);
l2.setBounds(50,75,400,25);
l3.setBounds(50,150,200,25);
l4.setBounds(50,190,200,25);
l5.setBounds(50,220,200,25);
l6.setBounds(50,260,200,25);
b1.setBounds(150,425,60,50);
d1.add(l1);
d1.add(l2);
d1.add(l3);
d1.add(l4);
d1.add(l5);
d1.add(l6);
d1.add(b1);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent we)
{
d1.dispose();
}
});
d1.setVisible(true);
}
});
//Adding JMenu Items to the JMenu
m1.add(m11);
m1.add(m14);
m1.add(m12);
m1.add(m13);
m1.add(m15);
m1.addSeparator();
m1.add(m16);
m2.add(m21);
m2.addSeparator();
m2.add(m22);
m2.add(m23);
m2.add(m24);
m2.add(m25);
m2.addSeparator();
m2.add(m26);
m3.add(m31);
m3.add(m32);
m4.add(m41);
m4.add(m42);
m5.add(m51);
m5.addSeparator();
m5.add(m52);
m5.add(m53);
m5.add(m54);
m5.add(m541);
m5.add(m55);
m5.addSeparator();
m5.add(m56);
m6.add(m61);
m6.add(m62);
m7.add(m71);
m7.addSeparator();
m7.add(m72);
//Adding JMenu to JMenu Bar
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
mb.add(m5);
mb.add(m6);
mb.add(m7);
//Setting the JMenu Bar
//Addng listeners to each JMenu
setJMenuBar(mb);
}
catch(Exception e){}
}
//Event Handeled for Window JMenu items
public void itemStateChanged(ItemEvent e)
{
//System.out.println("Hi");
if(m61.getState())
{
ta1.setBounds(5,43,790,545);
m62.setState(false);
validate();
}
else
{
ta1.setBounds(5,43,790,360);
validate();
}
if(m62.getState())
{
ta2.setVisible(true);
validate();
}
else
{
ta2.setVisible(false);
validate();
}
}
}
class ResultSetTableModel extends AbstractTableModel
{
private Connection connection;
private Statement statement;
private ResultSet resultSet;
private ResultSetMetaData metaData;
private int numberOfRows;
private boolean connectedToDatabase=false;
public ResultSetTableModel(String driver,String url,String
username,String password,String query)throws Exception
{
Class.forName(driver);
connection=DriverManager.getConnection(url,username,password);
statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
connectedToDatabase=true;
setQuery(query);
}
public Class getColumnClass(int column)throws IllegalStateException
{
if(!connectedToDatabase)
throw new IllegalStateException("Not Connected to Database");
try
{
String className=metaData.getColumnClassName(column+1);
}
catch(Exception exception)
{
exception.printStackTrace();
}
return Object.class;
}
public int getColumnCount()throws IllegalStateException
{
if(!connectedToDatabase)
throw new IllegalStateException("Not Connected to Database");
try
{
return metaData.getColumnCount();
}
catch(SQLException sqlException)
{
sqlException.printStackTrace();
}
return 0;
}
public String getColumnName(int column)throws IllegalStateException
{
if(!connectedToDatabase)
throw new IllegalStateException("Not Connected to Database");
try
{
return metaData.getColumnName(column +1);
}
catch(SQLException sqlException)
{
sqlException.printStackTrace();
}
return " ";
}
public int getRowCount()
{
if(!connectedToDatabase)
{
throw new IllegalStateException("Not connected to Database");
}
return numberOfRows;
}
public Object getValueAt(int row,int column)throws
IllegalStateException
{
if(!connectedToDatabase)
throw new IllegalStateException("Not Connected to DataBase");
try
{
resultSet.absolute(row+1);
return resultSet.getObject(column+1);
}
catch(SQLException sqlException)
{
sqlException.printStackTrace();
}
return " ";
}
public void setQuery(String query)throws
SQLException,IllegalStateException
{
if(!connectedToDatabase)
throw new IllegalStateException("Not Connected to Database");
resultSet=statement.executeQuery(query);
metaData=resultSet.getMetaData();
resultSet.last();
numberOfRows=resultSet.getRow();
fireTableStructureChanged();
}
public void disconnectFromDatabase()
{
if(connectedToDatabase)
{
try
{
resultSet.close();
statement.close();
connection.close();
}
catch(SQLException sqlException)
{
sqlException.printStackTrace();
}
finally
{
connectedToDatabase=false;
}
}
}
}
class DisplayQueryResults extends JFrame
{
static final String DRIVER="com.mysql.jdbc.Driver";
static final String DATABASE_URL="jdbc:mysql://localhost/hostel";
static final String USERNAME="root";
static final String PASSWORD="nettech";
static final String DEFAULT_QUERY="select * from rooms";
private ResultSetTableModel tableModel;
private JTextArea queryArea;
public DisplayQueryResults()
{
super("Displaying Query Results");
try
{
tableModel=new
ResultSetTableModel(DRIVER,DATABASE_URL,USERNAME,PASSWORD,DEFAULT_QUERY);
queryArea=new JTextArea(DEFAULT_QUERY,3,100);
queryArea.setWrapStyleWord(true);
queryArea.setLineWrap(true);
JScrollPane scrollPane=new
JScrollPane(queryArea,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
JButton submitButton=new JButton("Submit Query");
Box boxNorth=Box.createHorizontalBox();
boxNorth.add(scrollPane);
boxNorth.add(submitButton);
JTable resultTable=new JTable(tableModel);
add(boxNorth,BorderLayout.NORTH);
add(new JScrollPane(resultTable),BorderLayout.CENTER);
submitButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
tableModel.setQuery(queryArea.getText());
}
catch(SQLException sqlException)
{
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database
error",JOptionPane.ERROR_MESSAGE);
//try to execute default query
try
{
tableModel.setQuery(DEFAULT_QUERY);
queryArea.setText(DEFAULT_QUERY);
}
catch(SQLException sqlException2)
{
JOptionPane.showMessageDialog(null,sqlException2.getMessage(),"Database
error",JOptionPane.ERROR_MESSAGE);
tableModel.disconnectFromDatabase();
System.exit(1);
}
}
}
});
}
catch(ClassNotFoundException classNotFound)
{
JOptionPane.showMessageDialog(null,"Database Driver not
Found","Database error",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
catch(SQLException sqlException)
{
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database
Error",JOptionPane.ERROR_MESSAGE);
tableModel.disconnectFromDatabase();
System.exit(1);
}
catch(Exception e)
{
}
addWindowListener(
new WindowAdapter()
{
public void windowClosed(WindowEvent event)
{
tableModel.disconnectFromDatabase();
System.exit(0);
}
});
setSize(400,200);
setVisible(true);
}
}
public class javaEditor extends javaIde
{
public static void main(String ar[])throws Exception
{
javaIde f=new javaIde();
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
//System.exit(0);
}
});
}
}