3 Replies Latest reply on Apr 25, 2018 8:28 PM by hphanjra-JavaNet

    java sms send/recieve

    hphanjra-JavaNet

      Is there any better(free/no third party) SMS application where I can receive or send SMS messages?

        • 1. Re: java sms send/recieve
          hphanjra-JavaNet

          [code]

          package FinCal;

          import java.awt.*;
          import java.awt.event.*;
          import java.util.EventObject;
          import javax.swing.*;
          import javax.swing.table.*;

          public class PanelInTable {

              private JFrame frame;
              private JTable CompTable = null;
              private PanelTableModel CompModel = null;
              static public JButton addButton = null;

              public static void main(String args[]) {
                  try {
                      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
                      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                  } catch (Exception fail) {
                  }
                  SwingUtilities.invokeLater(new Runnable() {

                      @Override
                      public void run() {
                          new PanelInTable().makeUI();
                      }
                  });
                 try {Thread.sleep(2000);}catch(Exception e) {}
                  if (addButton != null){
                  for(int i=0;i< 1000;i++)
                   addButton.doClick();
                  
                  }else {
                   System.out.println(" addbutton is null");
                  }
             
                  try {Thread.sleep(2000);}catch(Exception e) {}
                 
            
             
              }

              public void makeUI() {
                  CompTable = CreateCompTable();
                  JScrollPane CompTableScrollpane = new JScrollPane(CompTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                          JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                  JPanel bottomPanel = CreateBottomPanel();
                  frame = new JFrame("Comp Table Test");
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.add(CompTableScrollpane, BorderLayout.CENTER);
                  frame.add(bottomPanel, BorderLayout.SOUTH);
                  frame.setPreferredSize(new Dimension(800, 400));
                  frame.setLocation(150, 150);
                  frame.pack();
                  frame.setVisible(true);
              }

              public JTable CreateCompTable() {
                  CompModel = new PanelTableModel();
                  CompModel.addRow();
                  JTable table = new JTable(CompModel);
                  table.setRowHeight(new CompCellPanel().getPreferredSize().height);
                  table.setTableHeader(null);
                  PanelCellEditorRenderer PanelCellEditorRenderer = new PanelCellEditorRenderer();
                  table.setDefaultRenderer(Object.class, PanelCellEditorRenderer);
                  table.setDefaultEditor(Object.class, PanelCellEditorRenderer);
                  return table;
              }

              public JPanel CreateBottomPanel() {
                  addButton = new JButton("Add Comp");
                  addButton.addActionListener(new ActionListener() {

                      @Override
                      public void actionPerformed(ActionEvent ae) {
                          Object source = ae.getSource();
                          if (source == addButton) {
                              CompModel.addRow();
                          }
                      }
                  });
                  JPanel panel = new JPanel(new GridBagLayout());
                  panel.add(addButton);
                
                  return panel;
              }
          }

          class PanelCellEditorRenderer extends AbstractCellEditor implements TableCellRenderer, TableCellEditor {

              private static final long serialVersionUID = 1L;
              private CompCellPanel renderer = new CompCellPanel();
              private CompCellPanel editor = new CompCellPanel();

              @Override
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                  renderer.setComp((Comp) value);
                  return renderer;
              }

              @Override
              public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                  editor.setComp((Comp) value);
                  return editor;
              }

              @Override
              public Object getCellEditorValue() {
                  return editor.getComp();
              }

              @Override
              public boolean isCellEditable(EventObject anEvent) {
                  return true;
              }

              @Override
              public boolean shouldSelectCell(EventObject anEvent) {
                  return false;
              }
          }

          class PanelTableModel extends DefaultTableModel {

              private static final long serialVersionUID = 1L;

              @Override
              public int getColumnCount() {
                  return 1;
              }

              public void addRow() {
                  super.addRow(new Object[]{new Comp(0, 0, "", "")});
              }
          }

          class Comp {

              public int type;
              public int relation;
              public String lower;
              public String upper;

              public Comp(int type, int relation, String lower, String upper) {
                  this.type = type;
                  this.relation = relation;
                  this.lower = lower;
                  this.upper = upper;
              }
          }

          class CompCellPanel extends JPanel {

              private static final long serialVersionUID = 1L;
              private JLabel labelWith = new JLabel("With ");
              private JComboBox typeCombo = new JComboBox(new Object[]{"height", "length", "volume"});
              private JComboBox relationCombo = new JComboBox(new Object[]{"above", "below", "between"});
              private JTextField lowerField = new JTextField();
              private JLabel labelAnd = new JLabel(" Label And ");
              private JTextField upperField = new JTextField();
              private JButton removeButton = new JButton("remove");

              CompCellPanel() {
                  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
                  relationCombo.addActionListener(new ActionListener() {

                      @Override
                      public void actionPerformed(ActionEvent e) {
                          enableUpper(relationCombo.getSelectedIndex() == 2);
                      }
                  });
                  enableUpper(false);
                  removeButton.addActionListener(new ActionListener() {

                      @Override
                      public void actionPerformed(ActionEvent e) {
                          JTable table = (JTable) SwingUtilities.getAncestorOfClass(JTable.class, (Component) e.getSource());
                          int row = table.getEditingRow();
                          table.getCellEditor().stopCellEditing();
                          ((DefaultTableModel) table.getModel()).removeRow(row);
                      }
                  });
                  add(labelWith);
                  add(typeCombo);
                  add(relationCombo);
                  add(lowerField);
                  add(labelAnd);
                  add(upperField);
                  add(Box.createHorizontalStrut(100));
                  add(removeButton);
              }

              private void enableUpper(boolean enable) {
                  labelAnd.setEnabled(enable);
                  upperField.setEnabled(enable);
              }

              public void setComp(Comp Comp) {
                  typeCombo.setSelectedIndex(Comp.type);
                  relationCombo.setSelectedIndex(Comp.relation);
                  lowerField.setText(Comp.lower);
                  upperField.setText(Comp.upper);
                  enableUpper(Comp.relation == 2);
              }

              public Comp getComp() {
                  return new Comp(typeCombo.getSelectedIndex(), relationCombo.getSelectedIndex(), lowerField.getText(), upperField.getText());
              }
          }

           

          [/code]

          • 2. Re: java sms send/recieve
            hphanjra-JavaNet

            package FinCal;

            import java.awt.BorderLayout;
            import java.awt.EventQueue;
            import java.text.SimpleDateFormat;
            import java.util.Date;

            import javax.swing.JFrame;
            import javax.swing.JPanel;
            import javax.swing.SpinnerDateModel;
            import javax.swing.border.Border;
            import javax.swing.border.EmptyBorder;
            import javax.swing.text.DateFormatter;
            import javax.swing.JSpinner;
            import javax.swing.JTextField;

            import java.awt.Color;
            import java.awt.event.MouseAdapter;
            import java.awt.event.MouseEvent;
            import java.awt.event.ActionListener;
            import java.awt.event.ActionEvent;

            public class SpinnerTest extends JFrame {

              DateTextField nj= null;// new DateTextField();
              private DateTextField dateStart;
            static Date date1 = null;
            static Date date2 = null;
            private JPanel contentPane;
            /**
              * @wbp.nonvisual location=71,459
              */
            private final JTextField textField = new JTextField();
            private JTextField textField_1;

            /**
              * Launch the application.
              */
            public static void main(String[] args) {
              System.out.println("SDFD");

              EventQueue.invokeLater(new Runnable() {
               public void run() {
                try {
                 SpinnerTest frame = new SpinnerTest();
                 frame.setVisible(true);
                } catch (Exception e) {
                 e.printStackTrace();
                }
               }
              });
            }

            /**
              * Create the frame.
              */
            public SpinnerTest() {
              getContentPane().setLayout(null);
             
            // textField_1 = new DateTextField();
            // textField_1.setBounds(10, 231, 86, 20);
            // getContentPane().add(textField_1);
            // textField_1.setColumns(10);
            // textField.setColumns(10);
             
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setBounds(100, 100, 450, 300);
              contentPane = new JPanel();
              contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
              setContentPane(contentPane);
              contentPane.setLayout(null);
             
              //SpinnerDateModel model = new SpinnerDateModel();
              JSpinner spinner = null;//new JSpinner(model);
            /*
              JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner, "dd.MM.yyyy");
              DateFormatter formatter = (DateFormatter)editor.getTextField().getFormatter();
              formatter.setAllowsInvalid(false); // this makes what you want
              formatter.setOverwriteMode(false);
              */
             
              SimpleDateFormat model = new SimpleDateFormat("MM.dd.yy");
              spinner = new JSpinner(new SpinnerDateModel());
              spinner.setEditor(new JSpinner.DateEditor(spinner, model.toPattern()));
             
             
            // JSpinner spinner = new JSpinner();
              spinner.setBounds(48, 119, 127, 86);
             
             
              dateStart= new DateTextField();
              dateStart.setBackground(Color.WHITE);

             
              System.out.println(" Date value -->"+dateStart.getText());
              dateStart.setBounds(48, 11, 127, 20);
             
              contentPane.add(dateStart);
              contentPane.add(spinner);
             
              DateTextField dateEnd = new DateTextField();
              date1 = dateStart.getDate();
              date2 = dateEnd.getDate();
             
             
              dateEnd.addMouseListener(new MouseAdapter() {
               @Override
               public void mouseClicked(MouseEvent arg0) {
                try {Thread.sleep(200);
                date2 = dateEnd.getDate();
                }catch(Exception k) {}
                System.out.println(daysBetween(date1,date2)+" From main END Date value -->"+ date2);
               }
              });

              dateStart.addMouseListener(new MouseAdapter() {
               @Override
               public void mouseClicked(MouseEvent arg0) {
                try {Thread.sleep(200);
                date1 = dateStart.getDate();
                }catch(Exception k) {}
                System.out.println(daysBetween(date1,date2)+" From main Start Date value -->"+ date1);
             
               }
              });
             
             
              dateEnd.setBackground(Color.WHITE);
              dateEnd.setBounds(48, 42, 127, 20);
              contentPane.add(dateEnd);
            }

              public int daysBetween(Date d1, Date d2){
                       return (int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
               }
            }

            • 3. Re: java sms send/recieve
              hphanjra-JavaNet

               

              FinCal;


              java.awt.BorderLayout;


              java.awt.Color;


              java.awt.Cursor;


              java.awt.Dimension;


              java.awt.FlowLayout;


              java.awt.Font;


              java.awt.Frame;


              java.awt.GridLayout;


              java.awt.Point;


              java.awt.event.ActionEvent;


              java.awt.event.ActionListener;


              java.awt.event.MouseAdapter;


              java.awt.event.MouseEvent;


              java.text.ParseException;


              java.text.SimpleDateFormat;


              java.util.Calendar;


              java.util.Date;

               

              javax.swing.JButton;


              javax.swing.JDialog;


              javax.swing.JLabel;


              javax.swing.JPanel;


              javax.swing.JSpinner;


              javax.swing.JTextField;


              javax.swing.SpinnerNumberModel;


              javax.swing.SwingConstants;


              javax.swing.SwingUtilities;


              javax.swing.border.LineBorder;


              javax.swing.event.ChangeEvent;


              javax.swing.event.ChangeListener;

               

              class DateTextField extends JTextField {

               

              private static String DEFAULT_DATE_FORMAT = "MM/dd/yyyy";

               

              private static final int DIALOG_WIDTH = 200;

               

              private static final int DIALOG_HEIGHT = 200;

               

              private SimpleDateFormat dateFormat;

               

              private DatePanel datePanel = null;

               

              private JDialog dateDialog = null;

               

              public JTextField getHH() {

               

              return this;

               

              public DateTextField() {

               

              this(new Date());

               

              public DateTextField(String dateFormatPattern, Date date) {

               

              this(date);

               

              DEFAULT_DATE_FORMAT = dateFormatPattern;

               

              public DateTextField(Date date) {

               

              date);

               

              false);

               

              new Cursor(Cursor.HAND_CURSOR));

               

              private void addListeners() {

               

              new MouseAdapter() {

               

              public void mouseClicked(MouseEvent paramMouseEvent) {

               

              if (datePanel == null) {

               

              datePanel = new DatePanel();

               

              point = getLocationOnScreen();

               

              point.y = point.y + 30;

               

              datePanel, point);

               

              private void showDateDialog(DatePanel dateChooser, Point position) {

               

              owner = (Frame) SwingUtilities

               

              this);

               

              if (dateDialog == null || dateDialog.getOwner() != owner) {

               

              dateDialog = createDateDialog(owner, dateChooser);

               

              dateDialog.setLocation(getAppropriateLocation(owner, position));

               

              dateDialog.setVisible(true);

               

              private JDialog createDateDialog(Frame owner, JPanel contentPanel) {

               

              dialog = new JDialog(owner, "Date Selected", true);

               

              dialog.setUndecorated(true);

               

              dialog.getContentPane().add(contentPanel, BorderLayout.CENTER);

               

              dialog.pack();

               

              dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT);

               

              return dialog;

               

              private Point getAppropriateLocation(Frame owner, Point position) {

               

              result = new Point(position);

               

              p = owner.getLocation();

               

              int offsetX = (position.x + DIALOG_WIDTH) - (p.x + owner.getWidth());

               

              int offsetY = (position.y + DIALOG_HEIGHT) - (p.y + owner.getHeight());

               

              if (offsetX > 0) {

               

              result.x -= offsetX;

               

              if (offsetY > 0) {

               

              result.y -= offsetY;

               

              return result;

               

              private SimpleDateFormat getDefaultDateFormat() {

               

              if (dateFormat == null) {

               

              dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);

               

              return dateFormat;

               

              public void setText(Date date) {

               

              out.println(" date -->"+date);

               

              date);

               

              //   System.out.println(date+"---- -----3---->>>>>>>>>>>"+getDate());


              public void setDate(Date date) {

               

              out.println("---- setting date---1------>>>>>>>>>>>"+date);

               

              super.setText(getDefaultDateFormat().format(date));

               

              // System.out.println("---- ---1------>>>>>>>>>>>"+getDate());


              public Date getDate() {

               

              try {

               

              return getDefaultDateFormat().parse(getText());

               

              catch (ParseException e) {

               

              return new Date();

               

              private class DatePanel extends JPanel implements ChangeListener {

               

              int startYear = 1980;

               

              int lastYear = 2050;

               

              backGroundColor = Color.gray;

               

              palletTableColor = Color.white;

               

              todayBackColor = Color.orange;

               

              weekFontColor = Color.blue;

               

              dateFontColor = Color.black;

               

              weekendFontColor = Color.red;

               

              controlLineColor = Color.pink;

               

              controlTextColor = Color.white;

               

              yearSpin;

               

              monthSpin;

               

              daysButton = new JButton[6][7];

               

              new BorderLayout());

               

              new LineBorder(backGroundColor, 2));

               

              backGroundColor);

               

              topYearAndMonth = createYearAndMonthPanal();

               

              topYearAndMonth, BorderLayout.NORTH);

               

              centerWeekAndDay = createWeekAndDayPanal();

               

              centerWeekAndDay, BorderLayout.CENTER);

               

              private JPanel createYearAndMonthPanal() {

               

              "createYearAndMonthPanal");

               

              cal = getCalendar();

               

              int currentYear = cal.get(Calendar.YEAR);

               

              int currentMonth = cal.get(Calendar.MONTH) + 1;

               

              panel = new JPanel();

               

              panel.setLayout(new FlowLayout());

               

              panel.setBackground(controlLineColor);

               

              yearSpin = new JSpinner(new SpinnerNumberModel(currentYear,

               

              startYear, lastYear, 1));

               

              yearSpin.setPreferredSize(new Dimension(56, 20));

               

              yearSpin.setName("Year");

               

              yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####"));

               

              yearSpin.addChangeListener(this);

               

              panel.add(yearSpin);

               

              yearLabel = new JLabel("Year");

               

              yearLabel.setForeground(controlTextColor);

               

              panel.add(yearLabel);

               

              monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth, 1,

               

              monthSpin.setPreferredSize(new Dimension(35, 20));

               

              monthSpin.setName("Month");

               

              monthSpin.addChangeListener(this);

               

              panel.add(monthSpin);

               

              monthLabel = new JLabel("Month");

               

              monthLabel.setForeground(controlTextColor);

               

              panel.add(monthLabel);

               

              return panel;

               

              private JPanel createWeekAndDayPanal() {

               

              "createWeekAndDayPanal");

               

              colname[] = { "S", "M", "T", "W", "T", "F", "S" };

               

              panel = new JPanel();

               

              panel.setFont(new Font("Arial", Font.PLAIN, 10));

               

              panel.setLayout(new GridLayout(7, 7));

               

              panel.setBackground(Color.white);

               

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

               

              cell = new JLabel(colname[i]);

               

              cell.setHorizontalAlignment(JLabel.RIGHT);

               

              if (i == 0 || i == 6) {

               

              cell.setForeground(weekendFontColor);

               

              else {

               

              cell.setForeground(weekFontColor);

               

              panel.add(cell);

               

              int actionCommandId = 0;

               

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

               

              for (int j = 0; j < 7; j++) {

               

              numBtn = new JButton();

               

              numBtn.setBorder(null);

               

              numBtn.setHorizontalAlignment(SwingConstants.RIGHT);

               

              numBtn.setActionCommand(String

               

              actionCommandId));

               

              numBtn.setBackground(palletTableColor);

               

              numBtn.setForeground(dateFontColor);

               

              numBtn.addActionListener(new ActionListener() {

               

              public void actionPerformed(ActionEvent event) {

               

              source = (JButton) event.getSource();

               

              if (source.getText().length() == 0) {

               

              return;

               

              true);

               

              source.setForeground(todayBackColor);

               

              int newDay = Integer.parseInt(source.getText());

               

              cal = getCalendar();

               

              cal.set(Calendar.DAY_OF_MONTH, newDay);

               

              cal.getTime());

               

              dateDialog.setVisible(false);

               

              if (j == 0 || j == 6)

               

              numBtn.setForeground(weekendFontColor);

               

              else


              numBtn.setForeground(dateFontColor);

               

              daysButton[i][j] = numBtn;

               

              panel.add(numBtn);

               

              actionCommandId++;

               

              return panel;

               

              private Calendar getCalendar() {

               

              "----getCalendar---------"+getDate());

               

              calendar = Calendar.getInstance();

               

              calendar.setTime(getDate());

               

              return calendar;

               

              private int getSelectedYear() {

               

              "getSelectedYear");

               

              return ((Integer) yearSpin.getValue()).intValue();

               

              private int getSelectedMonth() {

               

              "getSelectedMonth");

               

              return ((Integer) monthSpin.getValue()).intValue();

               

              private void dayColorUpdate(boolean isOldDay) {

               

              "dayColorUpdate"+getDate());

               

              cal = getCalendar();

               

              int day = cal.get(Calendar.DAY_OF_MONTH);

               

              cal.set(Calendar.DAY_OF_MONTH, 1);

               

              int actionCommandId = day - 2 + cal.get(Calendar.DAY_OF_WEEK);

               

              int i = actionCommandId / 7;

               

              int j = actionCommandId % 7;

               

              if (isOldDay) {

               

              daysButton[i][j].setForeground(dateFontColor);

               

              else {

               

              daysButton[i][j].setForeground(todayBackColor);

               

              public void print(String content) {

               

              //System.out.println(content);


              private void reflushWeekAndDay() {

               

              "reflushWeekAndDay");

               

              cal = getCalendar();

               

              cal.set(Calendar.DAY_OF_MONTH, 1);

               

              int maxDayNo = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

               

              int dayNo = 2 - cal.get(Calendar.DAY_OF_WEEK);

               

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

               

              for (int j = 0; j < 7; j++) {

               

              s = "";

               

              if (dayNo >= 1 && dayNo <= maxDayNo) {

               

              s = String.valueOf(dayNo);

               

              daysButton[i][j].setText(s);

               

              dayNo++;

               

              false);

               

              public void stateChanged(ChangeEvent e) {

               

              "stateChanged");

               

              true);

               

              source = (JSpinner) e.getSource();

               

              cal = getCalendar();

               

              if (source.getName().equals("Year")) {

               

              cal.set(Calendar.YEAR, getSelectedYear());

               

              else {

               

              cal.set(Calendar.MONTH, getSelectedMonth() - 1);

               

              cal.getTime());