I fix that. I just want to reduce the size of JTabbedPane. How can i do that.I mean the JTabbedPane box size.

Thanks I fix that.One more issue. I want to move bottom panel little more up.

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

    public class GridBagLayoutTest

    {
        JPanel bottomPanel;
        JPanel topPanel;
        public GridBagLayoutTest()
        {
            JFrame frame = new JFrame("GridBag Layout Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationByPlatform(true);

            Container container = frame.getContentPane();
            container.setLayout(new GridBagLayout());

            topPanel = new JPanel();

            topPanel.setBackground(Color.BLUE);

            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            gbc.fill = GridBagConstraints.BOTH;

            container.add(topPanel, gbc);

            bottomPanel = new JPanel();

            bottomPanel.setBackground(Color.WHITE);

            gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 1;

            gbc.weightx = 1.0;
            gbc.weighty = 1.0;

            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            gbc.fill = GridBagConstraints.BOTH;

            container.add(bottomPanel, gbc);
  JTabbedPane tabbed=new JTabbedPane();

            tabbed.add(bottomPanel,"One Way");

            gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 2;

            gbc.weightx = 1.0;
            gbc.weighty = 1.0;

            gbc.fill = GridBagConstraints.BOTH;
            container.add(tabbed,gbc);

            frame.setSize(300, 400);
            frame.setVisible(true);
        }

        public static void main(String... args)
        {
            Runnable runnable = new Runnable()
            {
                public void run()
                {
                    new GridBagLayoutTest();
                }
            };
            SwingUtilities.invokeLater(runnable);
        }
    }
ali11 -1 Light Poster

Hi I am trying to move JTabbedPane down below top panel.I want it where the bottom panel begin.Thanks.

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

    public class GridBagLayoutTest

    {
        JPanel bottomPanel;
        JPanel topPanel;
        public GridBagLayoutTest()
        {
            JFrame frame = new JFrame("GridBag Layout Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLocationByPlatform(true);

             JTabbedPane tabbed=new JTabbedPane();

            tabbed.add(bottomPanel,"One Way");
            tabbed.setBounds(12, 200, 20, 20);
            //tabbed.setTabPlacement(JTabbedPane.BOTTOM);

            Container container = frame.getContentPane();
            container.setLayout(new GridBagLayout());

            topPanel = new JPanel();

            topPanel.setBackground(Color.BLUE);
            topPanel.setPreferredSize(new Dimension(290,80));
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            gbc.fill = GridBagConstraints.BOTH;

            container.add(topPanel, gbc);

            bottomPanel = new JPanel();
            bottomPanel.setPreferredSize(new Dimension(120,270));
            bottomPanel.setBackground(Color.WHITE);

          bottomPanel.add(topPanel);

            gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 1;

            gbc.weightx = 1.0;
            gbc.weighty = 1.0;

            gbc.anchor = GridBagConstraints.LAST_LINE_START;
            gbc.fill = GridBagConstraints.BOTH;

            container.add(bottomPanel, gbc);

            container.add(tabbed,new GridBagConstraints(0,0,1,1,1.0,1.0
        ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 4, 5, 4), -2, -1));

            frame.setSize(300, 400);
            frame.setVisible(true);
        }

        public static void main(String... args)
        {
            Runnable runnable = new Runnable()
            {
                public void run()
                {
                    new GridBagLayoutTest();
                }
            };
            SwingUtilities.invokeLater(runnable);
        }
    }

I give that number just an example I try bigger too but the result is same.

thanks i already use tabbed.setBounds(0, 20, 80, 40); but nothing change

ali11 -1 Light Poster

Hi I am creating a program in which I have 2 tabs. I want to make my tabs bigger in size so they can take whole panel space. Is there any way I can make both tabs size bigger. thanks

import java.awt.*;
    import static java.awt.Font.BOLD;
    import java.awt.event.*;
    import java.awt.event.*;
    import java.awt.event.ActionListener;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    import javax.swing.*;
    import static javax.swing.SwingConstants.CENTER;
    import javax.swing.border.*;
    import javax.swing.event.*;

    public class hotels extends JFrame{

        JButton hotel;
        JLabel image;
         JTabbedPane tabbed,tabbed1;
        JPanel panel;
        JPanel panel1;

        Container pane;
        JPanel panel2;
        JLabel departure;
        JLabel from;
        JLabel to;

        public hotels(){

             panel=new JPanel();
            panel.setBackground(Color.cyan);
            hotel=new JButton();
            hotel.setText("Hotels");

            Font myFont = new Font("Serif", Font.BOLD, 18);

            hotel.setFont(myFont);
            panel.setLayout(null);
            panel.add(hotel);

            hotel.setBounds(50, 80, 100, 40);

            image=new JLabel();

            image.setBounds(50,1,80,80);
            image.setBorder(BorderFactory.createLineBorder(Color.yellow));
            image.setBackground(Color.white);
            image.setIcon(new ImageIcon("2.gif"));
            panel.add(image);

           panel1=new JPanel();
            panel1.setLayout(null);

          tabbed=new JTabbedPane();

             tabbed.setBounds(10, 110, 20, 20);

             tabbed.setBorder(BorderFactory.createMatteBorder(24, 6, 12, 6, Color.blue));

              Font myFont1 = new Font("Serif", Font.BOLD, 18);
              tabbed.setFont(myFont1);

             tabbed.setBorder(BorderFactory.createTitledBorder("Search Flights"));

         tabbed.add( "Round Trip",panel1);

         panel2=new JPanel();
         panel2.setLayout(null);
         panel2.setBackground(Color.white);
         departure=new JLabel();
         departure.setText("Departure");

         Font f=new Font("Serif", Font.PLAIN,12);
         departure.setBounds(50,1,80,80);
         departure.setFont(f);
         panel2.add(departure);
           tabbed.add("One Way",panel2);
           from=new JLabel();
           from.setBackground(Color.blue);

           panel1.setBackground(Color.yellow);

            pane=getContentPane();

              pane.add(panel);

       image.addMouseListener(new MouseAdapter()

       {

          public void mouseClicked(MouseEvent e){
               if (e.getSource()==image){

          pane.removeAll();

          pane.add(tabbed);
          pane.revalidate();
          pane.repaint();

               }

           }

       }

       );

        }

        public static void main(String[] args) {

     hotels mw=new hotels();
      mw.setVisible(true);
      mw.setSize(300, 400);

        }

        }
ali11 -1 Light Poster

Hi i am trying to make taxi meter which shows the current price.Rightnow I have to click startmeter afterevery 1 minute than it's update the new price but I want it to update automatically once the price change after 1 minute instead of me pressing startmeter everytime.thanks for your help.

import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.event.ActionListener;
import javax.swing.Timer; 
import java.awt.event.*;

public class taximeter extends JFrame{

    JButton start;
    JButton end;
    JLabel total;
    JPanel panel;
    Container pane;
    long star=-1;
    long sto=-1;

    public taximeter(){

     super("Taxi Meter");

      JButton start=new JButton("Start meter");
      JButton stop=new JButton("Stop meter");
        JLabel total=new JLabel("$0.00");

     star=System.currentTimeMillis();

        panel=new JPanel();

        panel.setLayout(null);
        panel.setVisible(true);
        panel.add(start);
        panel.add(stop);
      panel.add(total);

        start.setBounds(40, 50, 120, 40);

        stop.setBounds(40, 125, 120, 40);

        total.setBounds(75, 5, 120, 40);

        Container pane=getContentPane();

        pane.add(panel);
        pane.setVisible(true);

        GregorianCalendar jc=new GregorianCalendar();
        int lj=jc.getTime().getHours();
        int tj=jc.get(Calendar.HOUR);
        int ne=jc.get(Calendar.MINUTE);
        int jx=jc.get(Calendar.SECOND);

        stop.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e){

                if(e.getSource()==stop){

                    total.setText("$ 5.00");

                }

            }
        }

        );

           start.addActionListener(new ActionListener()
                {
                    public void actionPerformed(ActionEvent e){

                        int ld=jc.get(Calendar.MINUTE);
                        int mi=ne-ld;
                        int kd=mi*2;
                        int jm=kd+5;
                        int bc=jc.get(Calendar.HOUR);
                        int dc=(ld-ne)*5;

                        if(e.getSource()==start){

                    sto = System.currentTimeMillis() - star;
                    long lp = sto/(60*1000)% 60;
                    long ts=(lp*3)+3;

                    String lq=Long.toString(ts);

                        total.setText(lq);

                        panel.setVisible(true);

                   }     

                        }

                });

    }

    public static void main(String[] args) {

  taximeter mw=new taximeter();
  mw.setVisible(true);
  mw.setSize(200, 200);

    }

    }

thanks but what does '.' mean

ali11 -1 Light Poster

File f=new File("c:/'.'"); // I know about file class just didn't understand what kind of file "c:/'.'" is.

File strRoot[]=f.listRoots();

ali11 -1 Light Poster
GregorianCalendar cal = new GregorianCalendar(year, month, 1);

nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);

som = cal.get(GregorianCalendar.DAY_OF_WEEK);

for (int i=1; i<=nod; i++){// plz explain this line

int row = new Integer((i+som-2)/7); // plz explain this line.

int column = (i+som-2)%7;// also this line.

mtblCalendar.setValueAt(i, row, column);

As i said before all buttons are working fine (clear, decrypted, exit)except encrypted button and when i debug i don't get any error.

even if you change that.It's still not working

when i type something and click at Encryption button. I don't get encrypted text.other buttons are working fine except this one.

ali11 -1 Light Poster

everything is working fine except Encryption button.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class encryption extends JPanel implements ActionListener {

   char [] str= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
   char [] str1={'1','2','3','4','5','6','7','8','9','0','!','@','#','$','%','^','&','*','(','_','_','+','=',',','.','?'};
   char [] a= new char [50];
   char [] b= new char [50];
   JLabel pt, et,dt;
   String k="";
    String l="";

   JTextField pf,ef,df;
   JButton encbutt, clebutt,decbutt,exibutt;

   public encryption(){

       pt=new JLabel("Plain Text");
          et=new JLabel("Encrypted Text");
          dt=new JLabel("Decrypted Text");

         pf= new JTextField(20);

        ef= new JTextField(20);

        df= new JTextField(20);

         encbutt= new JButton("Encryption");

        clebutt= new JButton("Clear");

          decbutt= new JButton("Decryption");

         exibutt= new JButton("Exit");

         ef.setEditable(false);
   df.setEditable(false);
     decbutt.setEnabled(false);

      setLayout(null);
       add(pt);
                add(et);
                add(dt);
                add(pf);
                add(ef);
                add(df);
                add(encbutt);
                add(clebutt);
                add(decbutt);

                add(exibutt);

      pt.setBounds(20, 20, 200,30);

        et.setBounds(20,80,200,30);

         dt.setBounds(20,140, 200,30);

          pf.setBounds(220,20,200,30);

           ef.setBounds(220,80,200,30);

            df.setBounds(220,140,200,30);

             encbutt.setBounds(30,200,160,30);

              clebutt.setBounds(30,240,160,30);

               decbutt.setBounds(240,200,160,30);

                exibutt.setBounds(240,240,160,30);

                decbutt.addActionListener(this);

                clebutt.addActionListener(this);

                exibutt.addActionListener(this);

   }

public void actionPerformed(ActionEvent ae)
 {
    String action=ae.getActionCommand();
    if(ae.equals("Encryption"))
    {
         k=pf.getText().toString().toLowerCase();
        if(k.equals(""))
        {
            pf.setFocusable(true);
            JOptionPane.showMessageDialog(this, "Please Enter Any text !", "Warning", JOptionPane.WARNING_MESSAGE);

        }
 else
        {
        decbutt.setEnabled(true);
        encbutt.setEnabled(false);

        a=k.toCharArray();
        for(int i=0;i<k.length();i++)
        {
            for(int j=0;j<26;j++)
            {
             if(a[i]==str[j])
             {
                 a[i]=str1[j];

             }
            }

        }
        for(int i=0;i<k.length();i++)
        {
          l=l+a[i] ;
        }
        ef.setText(l);

       // JOptionPane.showMessageDialog(bencrypt,l.toString(),"Message",JOptionPane.INFORMATION_MESSAGE);

    }
  }
 else if(action.equals("Decryption"))
    {
  String x=ef.getText().toString();
  String y="";
  if(x.equals(""))
  {
      JOptionPane.showMessageDialog(this,"No Encrypted Message","Warning",JOptionPane.WARNING_MESSAGE);
  }
 else
  {
  b=x.toCharArray();
   //JOptionPane.showMessageDialog(this,k.toString(),"Warning",JOptionPane.WARNING_MESSAGE);
  for(int i=0;i<x.length();i++)
  {
      for(int j=0;j<26;j++)
      {
      if(b[i]==str1[j])
      {
          b[i]=str[j];
          j=26;
      }
      }
  }
  for( int i=0;i<x.length();i++)
  {
      y=y+b[i];
  }
  df.setText(y);
  y="";
 }
 }
 else if(action.equals("Clear"))
    {

     pf.setText("");
     ef.setText("");
     df.setText("");
     pf.setFocusable(true);
     decbutt.setEnabled(false);
     encbutt.setEnabled(true);

    }
 else if(action.equals("Exit"))
    {
     System.exit(0);
 }
}

public static void main(String[] args) {

       JFrame n=new JFrame();
        n.getContentPane().add(new encryption());
        n.setSize(440,310);
        n.setVisible(true);
        n.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}
ali11 -1 Light Poster
  JMenuItem mItem[] ={copy,paste}; 
  for(int b=0;b<mItem.length;b++)
  {
  mItem[b].addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e)
       {
        String mItemCommand = e.getActionCommand();
        JTextArea copypaste = new JTextArea(scr.getText());

        if(mItemCommand=="Copy"){
        copypaste.select(0,scr.getText().length());
        copypaste.copy();

        }

        if(mItemCommand=="Paste"){
        copypaste.setText("");
        copypaste.paste();
        String num =copypaste.getText();
        try{double n=Double.parseDouble(num);
          if(num.indexOf(".")!=-1)
           isDecimal = false;
                isFirstDigit = false;
                if( n-((long)n)>0.0)  // I just didn't understand codes starting from here
                scr.setText(""+n);
                else
                scr.setText(""+((long)n));
                if(n>=Long.MAX_VALUE || n<=Long.MIN_VALUE){

                scr.setText("0");}
                }catch(NumberFormatException ex){}
          }

i fix that but why only exit button is working in my whole program. everything looks fine to me.thanks

import java.awt.*;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
import javax.swing.event.AncestorEvent;
    public class dic extends JFrame{
    public JLabel label2,label3,label4,label5;
    public JTextField ew,fw;
    public JTextArea txar1,txar2;
    public JPanel panel1,panel2,panel3,panel5;
    public JScrollPane scr1,scr2;
    public GridBagLayout layout1,layout2,layout3,layout4;
    public JTabbedPane tab1=new JTabbedPane();
    public JButton exit,ok,insert,clear,delete;
    dichash has=new dichash(26);

    public dic(){
        GridBagLayout layout1=new GridBagLayout();
GridBagLayout layout2=new GridBagLayout();
GridBagLayout layout3=new GridBagLayout();
GridBagLayout layout4=new GridBagLayout();

    exit=new JButton("exit");
    exit.setToolTipText("u will lost all data");
    panel1=new JPanel();
    panel1.setLayout(layout1);
    ok=new JButton("ok");
    insert=new JButton("insert");
    clear=new JButton("clear");
    delete=new JButton("delete");
    delete.setToolTipText("warning word will delete");
    label2=new JLabel("enter word do u want to find");
    label3=new JLabel("enter the word");
    label4=new JLabel("description");
    label5=new JLabel(new ImageIcon (getClass().getResource("2.gif")));
    panel2=new JPanel();
    panel2.setLayout(layout2);
    JScrollPane scr1=new JScrollPane();
    scr1=new JScrollPane(scr1.createHorizontalScrollBar());
    scr1=new JScrollPane(scr1.createVerticalScrollBar());
    scr1.setBackground(Color.yellow);
    panel3=new JPanel();
    panel3.setLayout(layout3);
    panel5=new JPanel();
    panel5.setLayout(layout4);
    JScrollPane scr2=new JScrollPane();
    scr2=new JScrollPane(scr2.createHorizontalScrollBar());
    scr2= new JScrollPane(scr2.createVerticalScrollBar());
    JTextField ew=new JTextField();
    JTextArea txar1=new JTextArea();
    JTextArea txar2=new JTextArea();
    JTextField fw=new JTextField();
    this.getContentPane().setLayout(layout1);
    tab1.add(panel1, "about");
    this.getContentPane().add(tab1,new GridBagConstraints(0,0,1,1,1.0,1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 4, 5, 4), -2, -1));
    tab1.add(panel2, "Search");
    tab1.add(panel3, "Enter");
    panel1.add(label5, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 0, 0, 282), 135, 101));
    panel1.add(exit, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(46, 63, 50, 0), 49, 4));
    exit.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(ActionEvent e){
    exit_ActionPerformed(e);
    }
    }
    );
    panel2.add(label2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 14, 0, 0), ...
ali11 -1 Light Poster

Can someobody tell me why i only see blank window.

import java.awt.*;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class dic extends JFrame{
public JLabel label1,label2,label3,label4,label5,titlel;
public JTextField ew,fw;
public JTextArea txar1,txar2;
public JPanel panel1,panel2,panel3,panel5;

public JScrollPane scr1,scr2;
public GridBagLayout layout1,layout2,layout3,layout4;
public JTabbedPane tab1=new JTabbedPane();
public JButton exit,ok,insert,clear,delete;

      dichash has=new dichash(26);
    public dic(){

        exit=new JButton("exit");

        exit.setToolTipText("u will lost all data");

      panel1=new JPanel();
      panel1.setLayout(layout1);
        ok=new JButton("ok");
        insert=new JButton("insert");
        clear=new JButton("clear");
        delete=new JButton("delete");
        delete.setToolTipText("warning word will delete");

       label2=new JLabel("enter word do u want to find");
       label3=new JLabel("enter the word");
       label4=new JLabel("description");
       label5=new JLabel(new ImageIcon (getClass().getResource("2.gif")));

       panel2=new JPanel();
       panel2.setLayout(layout2);

       JScrollPane scr1=new JScrollPane();
       scr1=new JScrollPane(scr1.createHorizontalScrollBar());
       scr1=new JScrollPane(scr1.createVerticalScrollBar());
       scr1.setBackground(Color.yellow);
       panel3=new JPanel();
       panel3.setLayout(layout3);
       panel5=new JPanel();
       panel5.setLayout(layout4);

       JScrollPane scr2=new JScrollPane();
       scr2=new JScrollPane(scr2.createHorizontalScrollBar());
       scr2= new JScrollPane(scr2.createVerticalScrollBar());
       JTextField ew=new JTextField();
       JTextArea txar1=new JTextArea();
       JTextArea txar2=new JTextArea();
       JTextField fw=new JTextField();
       this.getContentPane().setLayout(layout1);

       tab1.add(panel1, "about");

       this.getContentPane().add(tab1,new GridBagConstraints(0,0,1,1,1.0,1.0
             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 4, 5, 4), -2, -1));

       tab1.add(panel2, "Search");
       tab1.add(panel3, "Enter");
       panel1.add(label5, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 0, 0, 282), 135, 101));

       panel1.add(exit, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(46, 63, 50, 0), 49, 4));

       exit.addActionListener(new java.awt.event.ActionListener(){

           public void actionPerformed(ActionEvent e){
               exit_ActionPerformed(e);
           }

               }
       );

       panel2.add(label2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 14, 0, 0), 8, 25));

       panel2.add(ok,new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 14, 9, 13), 24, 1));
       ok.addActionListener(new java.awt.event.ActionListener(){

           public void actionPerformed(ActionEvent e){
               ok_ActionPerformed(e);
           }
       } ...
ali11 -1 Light Poster
getting following  error: incompatible types: vmpr cannot be converted to JFrame

JFrame VendingMachine = new vmpr();

        import java.awt.Container;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import javax.swing.JButton;
        import javax.swing.JLabel;
        import java.awt.*;
        import javax.swing.*;
        import javax.swing.JFrame;

        public class vmgu extends JFrame implements ActionListener {
            public JButton button[];
            public JLabel label;
            public JLabel label2;

            public vmpr Machine = new vmpr();

            public vmgu(){

                button=new JButton[12];
                label=new JLabel("balance"+ Machine.getbalance());
                label2=new JLabel("vmachine");
                JFrame myFrame=new JFrame();
                Container pane = getContentPane(); // Get the pane.
                pane.setLayout(new GridLayout(7,2));
                for (int i=0;i<6; i++)
                {
                    Machine.initialize();
                    button[i]= new JButton(Machine.getdesc(i) +" - " + Machine.pr(Machine.getprice(i)));

                }

             button[6]= new JButton ("Dollar");
             button[7]=new JButton("half dollar");
             button[8]=new JButton("quarter");
             button[9]=new JButton("dime");
             button[10]=new JButton("nickel");
             button[11]=new JButton("coinreturn");

             for (int i=0; i<6; i++){

                   button[i].addActionListener(this);
                     button[i+6].addActionListener(this);

             pane.add(label);
             pane.add(label2);
                     pane.add(button[i]);
                     pane.add(button[i+6]);
             }

            }

              public void actionPerformed(ActionEvent event){
                  boolean success;
                  Object tbutton=event.getSource();
                  Machine.initialize();
                  for(int i=6; i<12; i++){
                      if(tbutton==button[i]){

                      switch(i){
                          case 6:
                              Machine.addmoney(100);
                              break;

                          case 7:
                              Machine.addmoney(50);
                              break;
                          case 8:
                              Machine.addmoney(25);
                              break;
                          case 9:
                              Machine.addmoney(10);
                              break;
                          case 10:
                              Machine.addmoney(5);
                          case 11:
                              Machine.getprbalance();

                      }

                  }
                  }
                  for (int i=0; i<6; i++){

                      if (tbutton==button[i]){
                          success=Machine.buyitem(i);
                          Machine.getchange();

                          }
                      }

                    label.setText("balance"+ vmpr.getprbalance());

                  }

        public static void main(String args[]) {

                BuildMachine();
        }
            public static void BuildMachine() {
                JFrame VendingMachine = new vmpr();
                VendingMachine.show(); 
                }

        } 

        public class vmpr  {

            final static int pr0=105;
            final static int pr1=120;
            final static int pr2=150;
            final static int pr3=160;
            final static int pr4=170;
            final  static int pr5=180;

            final static String des0="pepsi";
            final static String des1="cocke";
            final static String des2="dipepsi";
            final static String des3="7up";
            final static String des4="drpepper";
            final static String des5="canadadry";

         public static int ...
ali11 -1 Light Poster
import java.util.ArrayList;
import javax.swing.JOptionPane;

public class ClientList
{
    private ArrayList<Client> clientData;
    private final String    NEW_LINE = "\n";

    private int cursor;

    //manager mode
    public ClientList ( )
    {
        clientData = new ArrayList<Client> ( );
        buildClientList ( );

        if (clientData.size ( )  != 0)
            cursor = 0; //not empty, place cursor at the start of the vector
        else
            cursor = -1;    //empty

    }

    //manager mode
    public void buildClientList ( )
    {

        String textStream = new FileOperations ( ).readFile ( );
        JOptionPane.showMessageDialog (null, "client file loaded");

        //build the client list
        parseTextStream (textStream);
    }

    //build a vector from data read from a xml text file
    public void parseTextStream (String textStream)
    {
        int len = textStream.length ( );
        Client newClient = null;

        while (len != 0)
        {
            //get a line that ends with "\n"

            int pos = textStream.indexOf (NEW_LINE);
            if (pos == -1)
                break;

            String aLine = textStream.substring (0,pos);

            //the rest of the text stream
            textStream = textStream.substring (pos+1);
            len = textStream.length ( );

            aLine = aLine.trim ( );

            pos = aLine.indexOf ("<client>");
            if (pos != -1)
            {
                newClient = new Client ( ); //start of a client
                continue;   //skip the rest of the loop
            }

            pos = aLine.indexOf ("</client>");
            if (pos != -1)      //end of a client
            {
                clientData.add(newClient);  //append to the vector
                continue;
            }

            pos = aLine.indexOf ("<name>");
            if (pos != -1)
            {
                //extract what's between the start and end tags
                String newName = extractData ("<name>",aLine,"</name>");
                newClient.setName (newName);
                continue;
            }

            pos = aLine.indexOf ("<id>");
            if (pos != -1)
            {
                String newId = extractData ...
ali11 -1 Light Poster
error: no suitable method found for toArray(int[])
         return intList.toArray(new int[intList.size()]);
                       ^
    method Collection.<T#1>toArray(T#1[]) is not applicable
      (inference variable T#1 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
    method List.<T#2>toArray(T#2[]) is not applicable
      (inference variable T#2 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
    method AbstractCollection.<T#3>toArray(T#3[]) is not applicable
      (inference variable T#3 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
    method ArrayList.<T#4>toArray(T#4[]) is not applicable
      (inference variable T#4 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
  where T#1,T#2,T#3,T#4 are type-variables:
    T#1 extends Object declared in method <T#1>toArray(T#1[])
    T#2 extends Object declared in method <T#2>toArray(T#2[])
    T#3 extends Object declared in method <T#3>toArray(T#3[])
    T#4 extends Object declared in method <T#4>toArray(T#4[])
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

Tool completed with exit code 1

 import java.util.ArrayList;

                import java.util.Arrays;

                public class HashFunction2 {

                    int[] theArray;
                    int arraySize;
                    int itemsInArray = 0;

                    public static void main(String[] args) {

                        HashFunction2 theFunc = new HashFunction2(31);

                        int[] elementsToAdd2 = { 100, 510, 170, 214, 268, 398,
                                235, 802, 900, 723, 699, 1, 16, 999, 890,
                                725, 998, 978, 988, 990, 989, 984, 320, 321,
                                400, 415, 450, 50, 660, 624 };

                        // Demonstrate how data normally follows patterns and how
                        // a non-prime sized array can cause havoc

                        int[] elementsToAdd3 = { 30, 60, 90, 120, 150, 180,
                                210, 240, 270, 300, 330, 360, 390, 420, 450,
                                480, 510, 540, 570, 600, 989, 984, 320, 321,
                                400, 415, 450, 50, 660, 624 };

                        theFunc.hashFunction2(elementsToAdd2, theFunc.theArray);

                        // theFunc.modThirty(); ...
ali11 -1 Light Poster

*getting following error.
duplicate found
Exception in thread "main" java.lang.NullPointerException

    at binarysearchtree.main(binarysearchtree.java:185)

Java Result: 1
here is my code*

        public class node<T>
        {
             public node<T>  root ;
            public T data;
            public node left;
            public node right;

            public node (T newData)
            {
                data = newData;
                left = null;
                right = null;
                root=null;  
            }

            public node ()
            {
                data = null;
                left = null;
                right = null;
            }

            public void setData (T newData)
            {
                data = newData;
            }

            public T getData ()
            {
                return data;
            }

            public void setLeft (node newLeft)
            {
                left = newLeft;
            }

            public node getLeft ()
            {
                return left;
            }

            public void setRight (node newRight)
            {
                right = newRight;
            }

            public node getRight ()
            {
                return right;
            }
            public node getRoot ()
            {
                return root;
            }

            public void setRoot (node newRoot)
            {
                root = newRoot;
            }

            public boolean equals (node theOther)
            {
                return this.data.equals (theOther.data);
            }

          public int compareTo (node theOther)
            {
                return ((Integer) (this.getData ())).compareTo ((Integer) (theOther.getData ()));
            }

        }

        public class binarysearchtree<T>  extends node<T>
        {
            public node root;
            public binarysearchtree ()
            {
                root=null;
            }

            public boolean empty ()
            {
                return(root==null);
            }

           public boolean addOne (T newMember)
            {
                boolean success = true;
                node<T> newNode = new node<T> (newMember);
                if (empty ())
                    setRoot (newNode);
                else
                {
                    node p = null;
                    node c = getRoot ();
                    int compare = 0;

                    while (c != null)
                    {
                        compare = newNode.compareTo (c);
                        if (compare == 0)
                        {
                            System.out.println ("duplicate found");
                            success = false;
                            return success;
                        }
                        else
                        {
                            p = c;
                            if ...
Thanks now i am getting following error
C:\Users\sher\Documents\Bluetooth Folder\LinkList1.java:20: error: unreachable statement
    Link current=head;
         ^
1 error
> > 
> > 
> >     i am getting following errors
> >     C:\Users\sher\Documents\Bluetooth Folder\LinkList1.java:12: error: constructor Link in class Link cannot be applied to given types;
> >         Link newLink= new Link(data, head);
> >                           ^
> >       required: int
> >       found: int,Link
> >       reason: actual and formal argument lists differ in length
> >     C:\Users\sher\Documents\Bluetooth Folder\LinkList1.java:81: error: incompatible types: int cannot be converted to Link
> >         Link count=0;
> >                    ^
> >     C:\Users\sher\Documents\Bluetooth Folder\LinkList1.java:83: error: bad operand types for binary operator '<'
> >         while (count<index)
> >                     ^
> >       first type:  Link
> >       second type: int
> >     C:\Users\sher\Documents\Bluetooth Folder\LinkList1.java:89: error: bad operand type Link for unary operator '++'
> >                 count++;
> >                      ^
> >     C:\Users\sher\Documents\Bluetooth Folder\LinkList1.java:134: error: incompatible types: Link cannot be converted to boolean
> >          if (head=null)
> >                  ^
> >     C:\Users\sher\Documents\Bluetooth Folder\LinkList1.java:140: error: incompatible types: Link cannot be converted to boolean
> >              if (current.next=null)
> >                              ^
> >     6 errors
> >     
> > 
> > 
> 
>
 class LinkList1
 {
   private Link head;

    public LinkList1(){
        head=null;

    }
    public void insertfirst(int data){
        Link newLink= new Link(data, head);
        head=newLink;
    }

public Link search (int key){
    if (head==null);
    System.out.println("empty list");
    return null;
    Link current=head;
    while (current.getData!=key)
    {
        if
                (current.next==null)

            return null;

    else
            current=current.next;
                    }
    return current;
            }

public Link delete (int key){
    Link current=head;
    Link previous=head;
    while (current.getData!=key)
    {
        if (current.next==null)
            return null;
        else
            if (current==head)
                head=head.next;
        else
                previous.next=current.next;

    }
     return current;

}

public void display (){
    System.out.println("first");
Link current=head;
while (current!=null)

{
    current.displaydata();
    current=current.next;

}

  System.out.println("");

}
public void addtorear(int x){
    Link newNode= new Link(x);
    if (head==null);
    head=newNode;
    Link current=head;
    current.next=newNode;
}
int get (int index){
    Link current=head;
    Link count=0;

    while (count<index)

    {
        if (current!=null)
        {
            current=current.next;
            count++;
        }
            else
            return 0;
    }
        if (current!=null)
        return current.getData;

        else

    return 0;

}

public int removefirst(){
 Link temp=head;
 if(head!=null)
 {
     head=head.next;
     return temp.getData;
 }
 else
     return 0;
 }

 public int removelast()
 {
 Link temp=head;
 if (temp==null)
     return 0;
 Link previous=head; //learn
 while(temp.next != null){
            previous = temp;
            temp = temp.next;
        }

        previous.next = null;
        return temp.getData;
    }

 public int indexof(int x){
     if (head=null)
         return 0;
     Link current=head;
     int count=0;
     while(current.getData!=x)
     {
         if (current.next=null)
             return 0;
         else
         {
             current=current.next;
          count++;
         }

     }
         return count;

     }

 public static void main(String [] args) {
     LinkList1 L=new LinkList1();

     L.insertfirst(5);
        L.insertfirst(15);
        L.insertfirst(25);

        L.display();
                Link a= L.search(5);
                if(a!=null)
                {
                    a.displaydata();
                    System.out.println("");

                }
                else
                    System.out.println("5 no found");

 Link b=L.search(20);
 if(b!=null)
 {
     b.displaydata();
     System.out.println("");
 }
 else
     System.out.println("20 not found");

 L.delete(15);
 L.display();
 L.insertfirst(50);
 L.display();
 L.delete(5);

        L.display();

        L.delete(50);

        L.display();

        L.addtorear(30);
        L.addtorear(22); ...

`

 class LinkList1 
 {
    private Link head;

    public LinkList1(){
        head=null;

    }
    public void insertfirst(int data){
        Link newLink= new Link(data, head);
        head=newLink;
    }

public Link search (int key){
    if (head=null);
    System.out.println("empty list");
    return null;
    Link current=head;
    while (current.getData!=key)
    {
        if
                (current.next==null)

            return null;

    else
            current=current.next;
                    }
    return current;
            }

public Link delete (int key){
    Link current=head;
    Link previous=head;
    while (current.getData!=key)
    {
        if (current.next==null)
            return null;
        else
            if (current==head)
                head=head.next;
        else
                previous.next=current.next;

    }
     return current;   

}

public void display (){
    System.out.println("first");
Link current=head;
while (current!=null)

{
    current.displaydata();
    current=current.next;

}

}
public void addtorear(int x){
    Link newNode= new Link(x);
    if (head=null);
    head=newNode;
    Link current=head;
    current.next=newNode;
}
int get (int index){
    Link current=head;
    Link count=0;

    while (count<index)

    {
        if (current!=null)
        {
            current=current.next;
            count++;
        }
            else 
            return 0;
    }
        if (current!=null)
        return current.getData;

        else

    return 0;

}
public int removefirst(){
 Link temp=head;
 if(head!=null)
 {
     head=head.next;
     return temp.getData;
 }
 else 
     return 0;
 }

 public int removelast()
 {
 Link temp=head;
 if (temp==null)
     return 0;
 Link previous=head; //learn
 while(temp.next != null){
            previous = temp;         
            temp = temp.next;      
        }                                

        previous.next = null;            
        return temp.getData;            
    }                     

 public int indexof(int x){
     if (head=null)
         return 0;
     Link current=head;
     int count=0;
     while(current.getData!=x)
     {
         if (current.next=null)
             return 0;
         else
         {
             current=current.next;
          count++;   
         }

     }
         return count;

     }

 public static void main(String [] args) {
     LinkList1 L=new LinkList1();

     L.insertfirst(5);
        L.insertfirst(15);
        L.insertfirst(25);

        L.display();
                Link a= L.search(5);
                if(a!=null)
                {
                    a.display();
                    System.out.println("");

                }
                else
                    System.out.println("5 no found");

 Link b=L.search(20);
 if(b!=null)
 {
     b.display();
     System.out.println("");
 }
 else
     System.out.println("20 not found");

 L.delete(15);
 L.display();
 L.insertfirst(50);
 L.display();
 L.delete(5);

        L.display();

        L.delete(50);

        L.display();

        L.addtorear(30);
        L.addtorear(22); ...

i update my code

ali11 -1 Light Poster

i just learn about single linkedlist and i am trying to create a program.

public class linklis {

    public static void main(String[] args) {
       LinkedList ab= new LinkedList();
       ab.add("1");
       ab.add("2");
       ab.add("4");
       ab.add("7");
       System.out.println("the list" + ab);
       System.out.println("remove 2nd element: " + ab.Delete(2));

       System.out.println(" - print linkedlist size: " + ab.size());
       System.out.println("the list" + ab);

    }
}

class LinkedList {
    private Node head;
    private int cursor;

    public LinkedList(){
    head=-1;
    cursor=-1;

    }
    public void add(int newMember){
        Node newData=new Node(newMember);
        newData.setLink(head);
        head=newData;

    }

    public boolean empty(){
       return head=null;

    }
    public int size(){
        return size;
    }

    public void setData(integer newdata){
        data=newdata;

    }

    public void setLink (node newlink){
       link=newlink;

    }

public int getData(){
    return data;
}

public int getLink(){
    return link;
}

public boolean Delete(int key){
    Node found=search(key);
    if (found==-1)
    {
        System.out.println("nothing to delete");

    return false;
    }

    else
    {
        if  (found==head)
        {
            head=found.getLink();
          System.out.println("keydeleted");
        }
          return true;

        }
    }
    public String toString(){

        String outString = "";
        if (!empty ())
        {
            resetCursor ();
            outString += (cursor + " ") ;
            while (hasNext ())
                outString += (getNext () + "  ");

        }
        return outString;
    }

    }
ali11 -1 Light Poster
        //************************************
        //Includes

        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        #include <math.h>

        //************************************
        //Globals
        int packed;

        //************************************
        //Function Prototypes

        int pack_value(int value, int size, int low_bit);
        int unpack_value(int holder, int size, int low_bit);
        void get_date(int holder, int day, int month, int year);
        void get_permissions(int permission, int clas, int *read , int *write , int *execute);
        int w_permission(int clas, int *read , int *write , int *execute);
        int take_permissions(int clas,int *r, int *w, int *e);

        //***********************************
        //Main function

        int main(int argc, char** argv) 
        {

            //Variables

            int d,m,y;          //date variables

            int r,w,e;          //permission variables

            int p1,p2,p3;       //packed class variables

            int i;
            int permissions;
            int day, month, year;
            char a;

            printf("DATE:\n");

            //getting day and packing it
            printf(" Day:"); 
            scanf("%d",&day);
            d = pack_value(day,31, 0);   //31 = 5 one's on the lower bits

            //getting month and packing it
            printf(" Month:");
            scanf("%d",&month);
            m=pack_value(month,15, 5);   //15 = 4 one's on the lower bits

            //getting Year and packing it
            printf(" Year:"); 
            scanf("%d",&year);
            y=pack_value(year,4095, 10); //4095 = 12 one's on the lower bits

            //Packing date in one variable
            packed = d|m|y;

            //Taking permissins
            printf("\n\nPermissions for Owner :\n");
            p1=take_permissions(1,&r,&w,&e);

            printf("\nPermissions for Group :");
            p2=take_permissions(2,&r,&w,&e);

            printf("\nPermissions for Others :");
            p3=take_permissions(3,&r,&w,&e);

            //packing permissions
            permissions=p1|p2|p3;

            //Unpacking date
            get_date( packed, &d, &m, &y);

            //Printing Date
            printf("\n\nDATE\n day:%d\n month:%d\n year:%d\n", d, m, y);

        //*****
        //Unpacking permissins and printing them

            for(i=1;i<=3;i++)
            {

                switch(i)
                {

                case 1:
                    printf("\nPermissions for Owner :");

                    get_permissions(permissions,i,&r,&w,&e);

                      if(r==1)

                        printf("read " );
                      if(w==1)
                        printf("Write " );
                      if(e==1)
                          printf("Execute " );

                      break;

                case 2:

                    printf("\nPermissions for Group :");

                    get_permissions(permissions,i,&r,&w,&e);

                      if(r==1)

                        printf("read " );
                      if(w==1)
                        printf("Write " ...
ali11 -1 Light Poster
how can i replace the array notation with pointer notation

        #include<stdio.h>
        #include<stdlib.h>
        #include <math.h> 

        /*  4 */ void run_sieve(char *, int);
        /*  5 */ void print_primes(char *, int);

        /*  6 */ int main()
                 {
        /*  7 */    int i, top;
        /*  8 */    printf("compute primes up to:  ");
        /*  9 */    scanf("%d", &top);
        /* 10 */    if (top < 2)
                    {
                       /* 2 is the lowest prime */
        /* 11 */       printf("must be at least 2\n");
        /* 12 */       return 1;                                        /* error exit */
                    }
        /* 13 */    top++;                    /* want top to appear as index in array */
        /* 14 */    char *a = malloc(top*sizeof(char));         /* allocate array a[] */
        /* 15 */    for (i = 2; i < top; i++)
        /* 16 */       a[i] = 1;      /* initialize all indices as "potential primes" */
        /* 17 */    run_sieve(a, top);
        /* 18 */    print_primes(a, top);
        /* 19 */    return 0;  /* just being compulsive about a return value for main */
                 }

                 /*
                 computes primes by marking positions a[i] for i
                 a composite number with 0
                 */
        /* 20 */ void run_sieve(char *a, int top)
                 {
                    /* need only remove multiples of primes of
                       i for i up to and including sqrt(top)
                    */
         int last_start = (int)sqrt(top);
        /* 22 */    int i, j;
        /* 23 */    for (i = 2; i <= last_start; i++)    /* remove multiples of i */
        /* 24 */       if (a[i])          /* need only remove multiples of primes */
        /* 25 */          for (j ...
Thanks in my PA1 file i am still getting following error
C:\Users\papa\Desktop\PA1.java:144: cannot find symbol
symbol  : class DynamicIntArray
location: class PA1
         private static void insertIntoDynamicArray(Integer[] numbers, DynamicIntArray array) {
                                                                       ^
C:\Users\papa\Desktop\PA1.java:72: cannot find symbol
symbol  : class DynamicIntArray
location: class PA1
                DynamicIntArray dynamicArray = new DynamicIntArray();
                ^
C:\Users\papa\Desktop\PA1.java:72: cannot find symbol
symbol  : class DynamicIntArray
location: class PA1
                DynamicIntArray dynamicArray = new DynamicIntArray();
                                                   ^
3 errors

Tool completed with exit code 1