⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smface.java

📁 这个是由于项目需要
💻 JAVA
字号:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import GSMModem.*;
import java.io.*;
import javax.swing.table.*;
import javax.swing.border.*;
public class SMFace extends JFrame implements ActionListener
{
    String telephone;                                                                                                                                                                                                                                                                                                       
    String mailContent;
	Mail mail=new Mail();
	JMenuBar bar;
	JMenu menu1;
	JMenu menu2;
	JMenuItem item1;
	JMenuItem item2;
	JMenuItem item3;
	JMenuItem item4;
	JMenuItem item5;
///////////////////////////////////////////////////////
	JButton button;
	JButton button2;
	JTextField field;
	JTextArea area;
	JTextArea display;
	JLabel telLabel;
	JLabel contentLabel;

///////////////////////////////////////////////////////
	JButton add;
	JButton modify;
	JButton del;
	Object a [][];
	Object columnName[]={"姓名","手机号"};
	JTable table;
///////////////////////////////////////////////////////
	JPanel siglePane;//单发短信面板
	JPanel multiPane;//群发短信面板
	JPanel contrPane;//通讯录面板
	JPanel pane;//总的面板
	File file;
	String totalString;//用来接收从文件读来的字符串
	//构造函数
	public SMFace()
    {
		super("短信发送平台");
		bar=new JMenuBar();
		menu1=new JMenu("功能");
		menu2=new JMenu("关于");
		item1=new JMenuItem("手动单点发送");
		item2=new JMenuItem("自动群发");
		item3=new JMenuItem("查看通讯录");
		item4=new JMenuItem("About");
		item5=new JMenuItem("退出");
		
		button=new JButton("发送");
		button2=new JButton("自动群发");
		field=new JTextField(25);
		area=new JTextArea(5,40);
		display=new JTextArea(6,44);
		siglePane=new JPanel();
		//multiPane=new JPanel();
		contrPane=new JPanel();
		pane=new JPanel();
		telLabel=new JLabel("手机号码");
		contentLabel=new JLabel("短信内容");
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				mail.RealseDevice();
				System.exit(0);
			}
		});
		//添加监听器
		item1.addActionListener(this);
		item2.addActionListener(this);
		item3.addActionListener(this);
		item4.addActionListener(this);
		item5.addActionListener(this);
		button.addActionListener(this);
		button2.addActionListener(this);
		
		menu1.add(item1);
		menu1.add(item2);
		menu1.add(item3);
		menu2.add(item4);
		menu2.add(item5);
		bar.add(menu1);
		bar.add(menu2);
		setJMenuBar(bar);
		
		//单发短信面板的定义
		Box telBox=Box.createHorizontalBox();
		telBox.add(telLabel);
		telBox.add(Box.createHorizontalStrut(5));
		telBox.add(field);
		telBox.add(Box.createHorizontalGlue());
		
		Box contentBox=Box.createHorizontalBox();
		contentBox.add(contentLabel);
		contentBox.add(Box.createHorizontalStrut(5));
		contentBox.add(new JScrollPane(area));
		contentBox.add(Box.createHorizontalGlue());
		
		Box buttonBox=Box.createHorizontalBox();
		buttonBox.add(Box.createHorizontalStrut(130));
		buttonBox.add(button);
		buttonBox.add(Box.createHorizontalStrut(50));
		buttonBox.add(button2);
		buttonBox.add(Box.createHorizontalGlue()); 
		
		Box box=Box.createVerticalBox();
		box.add(telBox);
		box.add(Box.createVerticalStrut(10));
		box.add(contentBox);
		box.add(Box.createVerticalStrut(10));
		box.add(buttonBox);
		box.add(Box.createVerticalStrut(10));
		box.add(new JScrollPane(display));
		box.add(Box.createVerticalGlue());
		siglePane.add(box);
		
		//通讯录面板的定义
		add=new JButton("添加联系人");
		add.addActionListener(this);
		modify=new JButton("修改");
		modify.addActionListener(this);
		del=new JButton("删除");
		del.addActionListener(this);
		a=new Object[50][2];
		table=new JTable(a,columnName);
		table.setPreferredScrollableViewportSize(new Dimension(400,210));//设置TABLE的大小  不然的话就是默认的大小 
		table.setShowGrid(true);
		Box buttonBox2=Box.createHorizontalBox();
		buttonBox2.add(Box.createHorizontalStrut(40));
		buttonBox2.add(add);
		buttonBox2.add(Box.createHorizontalStrut(40));
		buttonBox2.add(modify);
		buttonBox2.add(Box.createHorizontalStrut(40));
		buttonBox2.add(del);
		buttonBox2.add(Box.createHorizontalGlue());	
		
		Box tableBox=Box.createVerticalBox();
		tableBox.add(buttonBox2);
		tableBox.add(Box.createVerticalStrut(10));
		tableBox.add(new JScrollPane(table));
		tableBox.add(Box.createVerticalStrut(10));
		tableBox.add(Box.createVerticalGlue());
		//contrPane.add(buttonBox2,BorderLayout.NORTH);
		//contrPane.add(new JScrollPane(table),BorderLayout.CENTER);
		contrPane.add(tableBox);
		contrPane.setVisible(false);
		
		pane=new JPanel();
		pane.add(siglePane);
		pane.add(contrPane);
		display.setText("***************信息显示控制台*************\n");
		display.append("连接设备中,请等待...........\n");
		button2.setEnabled(false);
		setContentPane(pane);
		setBounds(100,100,510,350);
		setVisible(true);
		setResizable(false);
		
		mail.Init("COM1","9600","WYRQ-HYAT-RAXQ-YTQC");
		mail.Set();
		if(mail.Conn())
		{
			display.append("连接设备成功!\n");
		}
		else
		{
			display.append("连接设备失败!\n");
		}			
   }
	//文件的读取
	public String ReadFile()
	{
		file=new File("D:/mail.txt");
		int len=(int)file.length();
		byte [] buf=new byte[len];
		try
		{
			FileInputStream in=new FileInputStream(file);
			in.read(buf);
			in.close();		
		}
		catch(IOException e)
		{
			JOptionPane.showMessageDialog(null,"读取文件mail.txt时出现错误!");
		}
		return new String(buf);
		
	}

	//事件监听响应函数。。
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==button)
		{
			telephone=field.getText();
			mailContent=area.getText();
            if(mail.SendMail(telephone,mailContent))
            {
            	display.append("发送短信成功\n");
            }
            else
            {
            	display.append("发送短信失败!\n");
            }
		}
		if(e.getSource()==item1)
		{
			siglePane.setVisible(true);
			contrPane.setVisible(false);
			field.setEnabled(true);
			telLabel.setEnabled(true);
			contentLabel.setEnabled(true);
			area.setEnabled(true);
			button.setEnabled(true);
			button2.setEnabled(false);	
		}
		if(e.getSource()==item2)
		{
			siglePane.setVisible(true);
			contrPane.setVisible(false);
			field.setEnabled(false);
			telLabel.setEnabled(false);
			contentLabel.setEnabled(false);
			area.setEnabled(false);
			button.setEnabled(false);
			button2.setEnabled(true);
		}
		if(e.getSource()==button2)
		{
			display.append("群发短信运行中....");
			DeadThread dt=new DeadThread(mail);
            new Thread(dt).start();	
		}
		if(e.getSource()==item3)
		{
			siglePane.setVisible(false);
			contrPane.setVisible(true);
			DataConn conn=new DataConn();
			int i=0;
			try
			{
			conn.SqlQuery("select * from friends");
			while(conn.rs.next())
			{
				//a[i][0]=String.valueOf(conn.rs.getInt("Id"));
				a[i][0]=conn.rs.getString("name");
				a[i][1]=conn.rs.getString("telphone");
				i++;
			}
			//conn.conn.close();
			}
			catch(Exception e2)
			{
				JOptionPane.showMessageDialog(null,e2);
			}
		}
		if(e.getSource()==item5)
		{
			if (JOptionPane.YES_OPTION==JOptionPane.showConfirmDialog(this,"你确定要退出本系统吗?","确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE))
			{
				mail.RealseDevice();
				System.exit(0);
			}
		}
	   if(e.getSource()==add)
	   {
		   UserAdd useradd=new UserAdd();
	   }
	   if(e.getSource()==del)
	   {
		   UserDle userdel=new UserDle();
	   }
	   if(e.getSource()==modify)
	   {
		   UserModify usermodify=new UserModify();
	   }   
	}
	
	public static void main(String [] args)
	{
		SMFace smface =new SMFace();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -