hello friends
i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than it shows the scrollbar but do not show the scrolling tabs here is my code pls do help me if u can plsssssssssssssssssssssssssssssssssss
try1.java
//package pradeep1;
import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import java.sql.*; import java.lang.String.*; import java.awt.TextField.*;
public class try1 extends JPanel implements ActionListener,ItemListener,TextListener {
int form1row=160,form4row=0; int form2row=0,form3row=0,form5row=0; /*********************for insertion into database *********************/ String strfirstname=new String(); String strlastname=new String(); String strdesirename=new String(); String strpass=new String(); String strrepass=new String(); String stranswer=new String(); String strrecovery=new String(); String strmatchword=new String(); int ch_question; int strlocation; /*********************************************************/ ImageIcon img; JLabel create,change,image,your,can; JComboBox cb; Color c; JLabel fname,lname,dname,title,exmform1; JTextField tfname,tlname,tdname; JButton check; ButtonGroup ob; JRadioButton id1,id2,id3,id4; JLabel chooseid; JLabel pass,repass,dehome,question,exm,exm1,exm2; JTextField pass1,repass1; JCheckBox stay,enable,setgoogle; JComboBox ch; JTextField form4question; String form5str; JLabel form5ans,form5remail,form5location,form5word,form5if1,form5que,form5exm1,form5exm2,form5exm3,form5exm4,form5exm5,form5img; JLabel form5term,form5t1,form5t2,form5t3,form5t4,form5t11,form5t22; JTextField form5ans1,form5remain1,form5matchtext; JButton form5b,form5accept; ImageIcon form5img1,form5img2; JComboBox form5ch; TextArea form5ta; Connection con; Statement st; ResultSet rs; String Actionstr; try1() { setLayout(null); c=new Color(55,145,220); //Container cp=getContentPane(); setBackground(Color.white); img=new ImageIcon("googletitle.gif"); image=new JLabel(img); create=new JLabel("Create an Account"); create.setForeground(c); create.setFont(new Font("Times new Roman",Font.BOLD,25)); change=new JLabel("Change Language:"); your=new JLabel("your Google Account gives you access to Gmail and other Google services. if you already have"); can=new JLabel("a Google Account, you can sign in here."); your.setFont(new Font("Times new Roman",Font.PLAIN,14)); can.setFont(new Font("Times new Roman",Font.PLAIN,14)); cb=new JComboBox(); cb.addItem("English"); cb.addItem("Hindi"); add(cb); image.setBounds(30,6,130,70); create.setBounds(10,93,210,20); cb.setBounds(480,80,110,25); change.setBounds(360,80,210,20); change.setFont(new Font("Times new Roman",Font.PLAIN,14)); your.setBounds(10,130,540,20); can.setBounds(10,145,510,20); your.setFont(new Font("Times new Roman",Font.PLAIN,14)); can.setFont(new Font("Times new Roman",Font.PLAIN,14)); add(image); add(create); add(cb); add(change); add(your);add(can);
/************form1********************/ title=new JLabel("Get started with Gmail"); fname=new JLabel("First Name:"); lname=new JLabel("Last Name:"); dname=new JLabel("Desired Login Name:"); exmform1=new JLabel("Examples:jsmith,john.smith"); title.setFont(new Font("Times new Roman",Font.BOLD,18)); exmform1.setFont(new Font("Times new Roman",Font.PLAIN,15)); fname.setFont(new Font("Times new Roman",Font.BOLD,15)); lname.setFont(new Font("Times new Roman",Font.BOLD,15)); dname.setFont(new Font("Times new Roman",Font.BOLD,15)); tfname=new JTextField(8); tlname=new JTextField(8); tdname=new JTextField(8); check=new JButton("Check availability!"); form1row=160; title.setBounds(10,(10+form1row),210,25); fname.setBounds(10,(40+form1row),210,25); lname.setBounds(10,(70+form1row),210,25); dname.setBounds(10,(120+form1row),210,25); tfname.setBounds(160,(40+form1row),230,25); tlname.setBounds(160,(70+form1row),230,25); tdname.setBounds(160,(120+form1row),230,25); exmform1.setBounds(160,(140+form1row),210,25); check.setBounds(160,(180+form1row),180,20); add(title); add(fname); add(lname); add(dname); add(tfname); add(tlname); add(tdname); add(exmform1); add(check); check.addActionListener(this);
/**************FORM3****************/
pass=new JLabel("Choose a password:");
repass=new JLabel("Re-enter password:");
dehome=new JLabel("Default HomePage");
question=new JLabel("Security question:");
exm=new JLabel("Minimum of 8 character s in Length.");
exm1=new JLabel("Your default homepage in your browser is the first page that appears when ");
exm2=new JLabel("you open your browser.");
pass1=new JTextField(8);
repass1=new JTextField(8);
stay=new JCheckBox("Stay signed in",true);
enable=new JCheckBox("Enable Web History",true);
setgoogle=new JCheckBox("Set Google as my default homepage",true);
ch=new JComboBox();
ch.addItem("Choose a question...");
ch.addItem("What is name of your best Friend from childhood?");
ch.addItem("What was the name of your first teacher?");
ch.addItem("what is the name of your manager at your first job?");
ch.addItem("What was your first phone number?");
ch.addItem("What is your vehicle registration number?");
ch.addItem("Write my own question");
ch.setSelectedIndex(1);
form3row=340;
pass.setBounds(10,(30+form3row),210,20);
pass1.setBounds(160,(30+form3row),230,25);
exm.setBounds(160,(55+form3row),230,20);exm.setFont(new Font("Times new Roman",Font.PLAIN,14));
repass.setBounds(10,(85+form3row),210,20);
repass1.setBounds(160,(85+form3row),230,25);
stay.setBounds(160,(125+form3row),210,20);
enable.setBounds(160,(155+form3row),210,20);
dehome.setBounds(10,(185+form3row),210,20);
setgoogle.setBounds(160,(185+form3row),230,25);
exm1.setBounds(160,(210+form3row),460,20);
exm1.setFont(new Font("Times new Roman",Font.PLAIN,14));
exm2.setBounds(160,(230+form3row),210,20);
exm2.setFont(new Font("Times new Roman",Font.PLAIN,14));
question.setBounds(10,(250+form3row),210,20);
ch.setBounds(160,(250+form3row),330,25);
ch.addItemListener(this);
add(pass);
add(repass);
add(dehome);
add(pass1);
add(repass1);
add(stay);add(enable);
add(exm);
add(dehome);
add(setgoogle);
add(exm2);
add(exm1);
add(question);
add(ch);
/*********************************************form5***********************/ form5row=620; form5if1=new JLabel("if you forget your password we will ask for the answer to your security"); add(form5if1); form5que=new JLabel("question."); add(form5que); form5if1.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5que.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5ans=new JLabel("Answer:");add(form5ans); form5remail=new JLabel("Recovery email:");add(form5remail); form5exm1=new JLabel("This address is used to authenticate your account should you ever encounter"); form5exm2=new JLabel("problems or forget your password.if1 you do not have another email address,"); form5exm3=new JLabel("you may leave this field blank."); add(form5exm1); add(form5exm2); add(form5exm3); form5location=new JLabel("Location:");add(form5location); form5word=new JLabel("Word Verification:");add(form5word); form5exm4=new JLabel("type the Chracters you see in the picture below.");add(form5exm4); form5exm5=new JLabel("Letters are not case-sensative");add(form5exm5); form5exm5.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5img1=new ImageIcon("wordimage.jpg");//add(form5img1); form5img2=new ImageIcon("matchimage.jpg"); form5b=new JButton(form5img2); form5img=new JLabel(form5img1); form5term=new JLabel("Terms of service:");add(form5term); form5t1=new JLabel("Please check the Google Account information you've entered above(feel free"); form5t2=new JLabel("to change anything you like),and review the Terms of service below."); form5t3=new JLabel("With Gmail, you won't see blinking banner ads. Instead, we display ads you"); form5t4=new JLabel("might find useful that are relevant to the content of your messages."); add(form5t1); add(form5t2); add(form5t3); add(form5t4); form5ans1=new JTextField(8); form5remain1=new JTextField(8); form5matchtext=new JTextField(8); form5ch=new JComboBox(); form5ch.addItem("india"); form5ch.addItem("pakistan"); add(form5ch); form5if1.setBounds(160,5+form5row,330,20); form5que.setBounds(160,20+form5row,100,20); form5ans.setBounds(10,45+form5row,210,25); form5ans1.setBounds(160,45+form5row,270,25); form5remail.setBounds(10,80+form5row,210,20); form5remain1.setBounds(160,80+form5row,230,25); form5exm1.setBounds(160,105+form5row,450,20); form5exm2.setBounds(160,120+form5row,450,20); form5exm3.setBounds(160,135+form5row,340,20); form5exm1.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5exm2.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5exm3.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5location.setBounds(10,160+form5row,210,20); form5ch.setBounds(160,160+form5row,280,25); form5word.setBounds(10,190+form5row,210,25); form5exm4.setBounds(160,190+form5row,230,30); form5exm4.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5img.setBounds(160,210+form5row,210,100); form5matchtext.setBounds(160,310+form5row,210,25); form5b.setBounds(380,310+form5row,25,25); form5exm5.setBounds(160,330+form5row,230,25); form5term.setBounds(10,370+form5row,210,25); form5t1.setBounds(160,370+form5row,440,25); form5t2.setBounds(160,390+form5row,440,25); form5t3.setBounds(160,420+form5row,440,25); form5t4.setBounds(160,435+form5row,440,25); form5t1.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5t2.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5t3.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5t4.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5str=new String("Google terms of services \n\n\nwelcome to google"); form5ta=new TextArea(form5str,200,120); form5ta.setBounds(160,470+form5row,450,120); form5t11=new JLabel("By clicking on ''i accept''below you are agreeing to the Terms of service above"); form5t22=new JLabel("and both the program policy and the Private Policy"); form5t11.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5t22.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5t11.setBounds(160,620+form5row,410,25); form5t22.setBounds(160,640+form5row,410,25); form5accept=new JButton("I accept. Create my account."); form5accept.setBounds(210,690+form5row,260,20); add(form5if1); add(form5que); add(form5ans); add(form5ans1); add(form5remail); add(form5remain1); add(form5exm1); add(form5exm2); add(form5exm3); add(form5location); add(form5exm4); add(form5word); add(form5img); add(form5matchtext); add(form5b); add(form5exm5); add(form5term); add(form5t1); add(form5t2); add(form5t3); add(form5t4); add(form5ta); add(form5t11); add(form5t22); add(form5accept); form5accept.addActionListener(this); repass1.addActionListener(this); } public void textValueChanged(TextEvent e) { String password=pass1.getText(); String repassword=repass1.getText(); if(repassword.equals(password)) { JLabel passwordmatch=new JLabel("Password not match"); add(passwordmatch); passwordmatch.setBounds(430,form3row+50,100,25); } } public void actionPerformed(ActionEvent ae) { Actionstr=ae.getActionCommand(); if(Actionstr.equals("Check availability!")) { chooseid=new JLabel("Choose One Of The USERNAME"); chooseid.setForeground(Color.red); add(chooseid); chooseid.setBounds(160,450,200,20); form2row=330; id1=new JRadioButton("pradeep.kumar11"); id2=new JRadioButton("p11.kumar"); id3=new JRadioButton("kumar_pradeep1169"); id4=new JRadioButton("pradee_kumar1169"); id1.setBackground(Color.white); id2.setBackground(Color.white); id3.setBackground(Color.white); id4.setBackground(Color.white); ob=new ButtonGroup(); ob.add(id1); ob.add(id2); ob.add(id3); ob.add(id4); id1.setBounds(160,(30+form2row),210,22); id2.setBounds(160,(50+form2row),210,22); id3.setBounds(160,(70+form2row),210,22); id4.setBounds(160,(90+form2row),210,22); add(id1); add(id2); add(id3); add(id4); repaint(); form3row=form2row+120; pass.setBounds(10,(30+form3row),210,20); pass1.setBounds(160,(30+form3row),230,25); exm.setBounds(160,(55+form3row),230,20);exm.setFont(new Font("Times new Roman",Font.PLAIN,14)); repass.setBounds(10,(85+form3row),210,20); repass1.setBounds(160,(85+form3row),230,25); stay.setBounds(160,(125+form3row),210,20); enable.setBounds(160,(155+form3row),210,20); dehome.setBounds(10,(185+form3row),210,20); setgoogle.setBounds(160,(185+form3row),230,25); exm1.setBounds(160,(210+form3row),460,20); exm1.setFont(new Font("Times new Roman",Font.PLAIN,14)); exm2.setBounds(160,(230+form3row),210,20); exm2.setFont(new Font("Times new Roman",Font.PLAIN,14)); question.setBounds(10,(250+form3row),210,20); form4row=250+form3row; ch.setBounds(160,(250+form3row),330,25); this.setSize(620,2000); form5row=form3row+290; form5if1.setBounds(160,5+form5row,330,20); form5que.setBounds(160,20+form5row,100,20); form5ans.setBounds(10,45+form5row,210,25); form5ans1.setBounds(160,45+form5row,270,25); form5remail.setBounds(10,80+form5row,210,20); form5remain1.setBounds(160,80+form5row,230,25); form5exm1.setBounds(160,105+form5row,450,20); form5exm2.setBounds(160,120+form5row,450,20); form5exm3.setBounds(160,135+form5row,340,20); form5location.setBounds(10,160+form5row,210,20); form5ch.setBounds(160,160+form5row,280,25); form5word.setBounds(10,190+form5row,210,25); form5exm4.setBounds(160,190+form5row,230,30); form5img.setBounds(160,210+form5row,210,100); form5matchtext.setBounds(160,310+form5row,210,25); form5b.setBounds(380,310+form5row,25,25); form5exm5.setBounds(160,330+form5row,230,25); form5term.setBounds(10,370+form5row,210,25); form5t1.setBounds(160,370+form5row,440,25); form5t2.setBounds(160,390+form5row,440,25); form5t3.setBounds(160,420+form5row,440,25); form5t4.setBounds(160,435+form5row,440,25); form5t11.setBounds(160,620+form5row,410,25); form5t22.setBounds(160,640+form5row,410,25); form5accept.setBounds(210,690+form5row,260,20); repaint(); } if(Actionstr.equals("I accept. Create my account.")) { System.out.println("karan"); boolean var_error=errorcheck(); if(var_error==true) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:gmaildata"); st=con.createStatement(); rs=st.executeQuery("select * from login"); st.executeUpdate("INSERT INTO login VALUES('"+strdesirename+"','"+strfirstname+"','"+strlastname+"','"+strpass+"','"+ch_question+"','"+stranswer+"','"+strrecovery+"','"+strlocation+"'"); /*while(rs.next()) { System.out.println(); }*/ con.close(); st.close(); repaint(); }catch(Exception e){} } } } public boolean errorcheck() { boolean flag=true; JLabel firstname,desirename,lastname,answer,recoverymail; firstname=new JLabel("EMPTY FIELD..."); lastname=new JLabel("EMPTY FIELD..."); desirename=new JLabel("EMPTY FIELD..."); answer=new JLabel("PROVIDE A ANSWER..."); recoverymail=new JLabel("PROVIDE RECOVERY MAIL "); strfirstname=tfname.getText(); strlastname=tlname.getText(); strdesirename=tdname.getText(); strpass=pass1.getText(); strrepass=repass1.getText(); stranswer=form5ans.getText(); strrecovery=form5remail.getText(); ch_question=ch.getSelectedIndex(); strlocation=form5ch.getSelectedIndex(); strmatchword=form5matchtext.getText(); System.out.println(tfname.getText()); System.out.print(strlastname); System.out.println("thik hai"); if(strfirstname.length()==0) { flag=false; System.out.println("fistname\n"); add(firstname); firstname.setForeground(Color.red); firstname.setBounds(430, form1row+40, 180, 25); } if(strlastname.length()==0) { flag=false; System.out.println("lastname\n"); add(lastname); lastname.setForeground(Color.red); lastname.setBounds(430, form1row+70, 180, 25); } if(strdesirename.length()==0) { flag=false; System.out.println("desirename\n"); add(desirename); desirename.setForeground(Color.red); desirename.setBounds(430, form1row+120, 180, 25); } if(!(strpass.equals(strrepass))) { flag=false; JLabel labelmatch=new JLabel("PASSWORD NOT MATCHES"); add(labelmatch); labelmatch.setForeground(Color.red); labelmatch.setBounds(430,form3row+85,180,25); } if(stranswer.length()==0) { flag=false; System.out.println("answer"); add(answer); answer.setForeground(Color.red); answer.setBounds(460,form5row+44,180,25); } if(strrecovery.length()==0) { flag=false; System.out.println("recovery mail"); add(recoverymail); recoverymail.setForeground(Color.red); recoverymail.setBounds(420,form5row+80,180,25); } repaint(); if(flag==false) return false; else return true; //}catch(Exception exception){}/ } public void itemStateChanged(ItemEvent ii) { int i=ch.getSelectedIndex(); if(i==6) { form4row=form3row+290; form4question=new JTextField(8); JLabel ll=new JLabel("Your own question"); add(ll); ll.setBounds(10,form4row,90,25); form4question.setBounds(160,form4row,330,25); add(form4question); form5row=form4row+40; form5if1.setBounds(160,5+form5row,330,20); form5que.setBounds(160,20+form5row,100,20); form5ans.setBounds(10,45+form5row,210,25); form5ans1.setBounds(160,45+form5row,270,25); form5remail.setBounds(10,80+form5row,210,20); form5remain1.setBounds(160,80+form5row,230,25); form5exm1.setBounds(160,105+form5row,450,20); form5exm2.setBounds(160,120+form5row,450,20); form5exm3.setBounds(160,135+form5row,340,20); form5location.setBounds(10,160+form5row,210,20); form5ch.setBounds(160,160+form5row,280,25); form5word.setBounds(10,190+form5row,210,25); form5exm4.setBounds(160,190+form5row,230,30); form5exm4.setFont(new Font("Times new Roman",Font.PLAIN,14)); form5img.setBounds(160,210+form5row,210,100); form5matchtext.setBounds(160,310+form5row,210,25); form5b.setBounds(380,310+form5row,25,25); form5exm5.setBounds(160,330+form5row,230,25); form5term.setBounds(10,370+form5row,210,25); form5t1.setBounds(160,370+form5row,440,25); form5t2.setBounds(160,390+form5row,440,25); form5t3.setBounds(160,420+form5row,440,25); form5t4.setBounds(160,435+form5row,440,25); form5ta.setBounds(160,470+form5row,450,120); form5t11.setBounds(160,620+form5row,410,25); form5t22.setBounds(160,640+form5row,410,25); form5accept.setBounds(210,690+form5row,260,20); }
}
and
mainframe.java
import java.awt.*; import java.awt.event.*; import javax.swing.*;
public class mainframe {
public static void main(String args[]) { JFrame jf=new JFrame("hello"); JPanel ob=new try1(); JScrollPane scrollBar=new JScrollPane(ob,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); jf.add(scrollBar); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(800,700); jf.setVisible(true); }
}
import java.awt.*; import javax.swing.*; public class AddScrollBarToJFrame{ public static void main(String args[]) { JScrollBar bar1 = new JScrollBar(JScrollBar.HORIZONTAL); JScrollBar bar2 = new JScrollBar(JScrollBar.VERTICAL); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.add(bar1, BorderLayout.SOUTH); contentPane.add(bar2, BorderLayout.EAST); frame.setSize(300, 150); frame.setVisible(true); } }
Ads