📄 applet1.java~853~
字号:
if (IsBlack==true) IsBlack=false; else IsBlack=true; this.getGraphics().clearRect(0,0,5*ImageCol,5*ImageRow); this.getGraphics().clearRect(250,100,250+1*ImageCol,100+1*ImageRow); } //清空操作 else if (x>53 && x<77 && y>104 && y<128 ) { for (int i=0;i<15;i++) { for (int j=0;j<75;j++) { IsBlack=true; Data[i][j]=0; } } IsBian=false; this.getGraphics().clearRect(0,0,5*ImageCol,5*ImageRow); this.getGraphics().clearRect(250,100,250+1*ImageCol,100+1*ImageRow); } else if (x>77 && x<101 && y>104 && y<128 ) { tf_Str.requestFocus(); tf_Str.selectAll(); Str_Command="文字"; IsBian=false; } else if (x>101 && x<125 && y>104 && y<128 ) { int tempData; for (int i=0;i<29;i++) { for (int j=0;j<99;j++) { tempData=Data[i][j]; Data[i][j]=OldData[i][j]; OldData[i][j]=tempData; } } if (IsBian==true) { if (IsBlack==true) IsBlack=false; else IsBlack=true; IsBian=false; } } else if (x>125 && x<149 && y>104 && y<128 ) { Str_Command="橡皮"; IsBian=false; } repaint(); */ } public void paint(Graphics g) { int row,col; g.drawString("按钮功能:",189,100); g.drawString("缩略图:",200,122); //画方格 for (row=0;row<=ImageRow;row++) g.drawLine(5,5*row+5,5+5*ImageCol,5*row+5); for (col=0;col<=ImageCol;col++) g.drawLine(5+5*col,5,5+5*col,5*ImageRow+5); //画所略图的方格 g.drawRect(250,110,ImageCol,ImageRow); for (row=0;row<ImageRow;row++){ for (col=0;col<ImageCol;col++) if (Data[row][col] == 1){ //画主要的图形 g.fillRect(5+5*col,5*row+5,5,5); //画缩略图形 g.fillRect(250+col,110+row,1,1); } } //绘制一蕞按钮 //绘制底色 g.setColor(Color.lightGray); g.fillRect(5,80,120,48); g.fillRect(126,105,23,23); g.setColor(Color.black); //绘制轮廓 g.drawRect(5,80,120,48); g.setColor(Color.white); g.drawLine(5,80,125,80); g.setColor(Color.black); g.drawLine(5,104,125,104); g.setColor(Color.white); g.drawLine(5,105,149,105); g.setColor(Color.white); g.drawLine(5,80,5,128); g.setColor(Color.black); g.drawLine(29,80,29,128); g.setColor(Color.white); g.drawLine(30,80,30,128); g.setColor(Color.black); g.drawLine(53,80,53,128); g.setColor(Color.white); g.drawLine(54,80,54,128); g.setColor(Color.black); g.drawLine(77,80,77,128); g.setColor(Color.white); g.drawLine(78,80,78,128); g.setColor(Color.black); g.drawLine(101,80,101,128); g.setColor(Color.white); g.drawLine(102,80,102,128); //加画橡皮 g.setColor(Color.lightGray); g.setColor(Color.black); g.drawLine(149,105,149,128); g.drawLine(126,128,149,128); g.setColor(Color.white); // g.drawLine(126,103,150,103); g.drawLine(126,104,126,128); //绘制图案 g.setColor(Color.black); //任意图形 Polygon p=new Polygon(); p.addPoint(9,84); p.addPoint(15,100); p.addPoint(20,90); p.addPoint(25,100); g.drawPolygon(p); //绘直线 g.drawLine(34,86,49,96); g.drawLine(34,87,49,97); //绘矩形 g.drawRect(57,86,16,14); //绘填充矩形 g.fillRect(82,86,16,14); //绘椭圆 g.drawOval(105,85,16,14); //绘填充椭圆 g.fillOval(10,110,16,14); //绘制取反图案 g.fillRect(33,108,16,14); g.drawRect(35,109,16,14); //绘制清空符号 g.drawLine(58,109,72,123); g.drawLine(58,110,72,124); g.drawLine(58,123,72,109); g.drawLine(58,124,72,110); //绘制文字图案 g.setFont(new Font("宋体",Font.BOLD,20)); g.drawString("A",84,123); //绘制箭头 g.drawLine(107,116,119,116); g.drawLine(107,116,112,111); g.drawLine(108,116,112,111); g.drawLine(107,116,112,121); g.drawLine(108,116,112,121); //绘制橡皮 g.drawRect(130,120,10,4); g.drawLine(130,120,135,110); g.drawLine(135,110,145,110); g.drawLine(145,110,145,114); g.drawLine(140,120,145,110); g.drawLine(140,124,145,114); g.setColor(Color.white); g.fillRect(131,121,9,3);/* Polygon p1=new Polygon(); p.addPoint(131,119); p.addPoint(139,119); p.addPoint(144,109); p.addPoint(136,109); g.fillPolygon(p1); */ //构造立体感 if (Str_Command=="自绘") { g.setColor(Color.black); g.drawLine(5,80,5,104); g.drawLine(5,80,29,80); g.setColor(Color.white); g.drawLine(29,80,29,104); g.drawLine(5,104,29,104); } else if (Str_Command=="直线") { g.setColor(Color.black); g.drawLine(30,80,30,104); g.drawLine(30,80,53,80); g.setColor(Color.white); g.drawLine(53,80,53,104); g.drawLine(30,104,53,104); } else if (Str_Command=="矩形") { g.setColor(Color.black); g.drawLine(54,80,54,104); g.drawLine(54,80,77,80); g.setColor(Color.white); g.drawLine(77,80,77,104); g.drawLine(54,104,77,104); } else if (Str_Command=="填充矩形") { g.setColor(Color.black); g.drawLine(78,80,78,104); g.drawLine(78,80,101,80); g.setColor(Color.white); g.drawLine(101,80,101,104); g.drawLine(78,104,101,104); } else if (Str_Command=="椭圆") { g.setColor(Color.black); g.drawLine(102,80,102,104); g.drawLine(102,80,125,80); g.setColor(Color.white); g.drawLine(125,80,125,104); g.drawLine(102,104,125,104); } else if (Str_Command=="填充椭圆") { g.setColor(Color.black); g.drawLine(5,105,5,128); g.drawLine(5,105,29,105); g.setColor(Color.white); g.drawLine(29,104,29,128); g.drawLine(5,128,29,128); } else if (Str_Command=="文字") { g.setColor(Color.black); g.drawLine(78,105,78,128); g.drawLine(78,105,101,105); g.setColor(Color.white); g.drawLine(101,105,101,128); g.drawLine(78,128,101,128); } else if (Str_Command =="橡皮") {g.setColor(Color.white); g.drawLine(149,105,149,128); g.drawLine(126,128,149,128); g.setColor(Color.black); g.drawLine(126,105,149,105); g.drawLine(126,105,126,128); } } }//end of the class //send message class buttonEvent implements ActionListener{ byte CodeString[]; //用于检查输入的数据是否合法 private boolean checkInfo(String info){ int i; char ctemp; for (i=0;i<info.length();i++){ ctemp = info.charAt(i); if (ctemp<'0'||ctemp>'9') return false; } return true; } public void actionPerformed(ActionEvent e){ //textField1.setText(getParameter("SendMobile")); if ((textField1.getText().length()!=11)||!checkInfo(textField1.getText())){ //进行提示,输入的手机号不足11位 WarningDialog WarningDialog1=new WarningDialog(getParentWindow(label1),"错误警告",false); WarningDialog1.setBounds(300, 300, 220, 100); WarningDialog1.setVisible(true); return; } if (e.getActionCommand()=="发送"){ ControlButton.setLabel("点击"); try{ //send the message EncodeString(); //it is for debug SendMessage(); //end of debug } catch (Exception error) { ControlButton.setLabel("错误"); } } } private void EncodeString(){ //将图形的编码编制成字符串 int rowindex,colindex,index;//index用来表示数组下标 byte Kind; char temp; String Sendingmobile; //记录了是谁进行发送的该条信息 Sendingmobile="13006047474"; //Sendingmobile = getParameter("SendMobile"); colindex=((ImageCol+7)/8)*ImageRow*2; //分析一下填入的信息是logo还是icon if (choice1.getSelectedIndex()==1) Kind = 0x0A; else Kind = 0x05; //this is written by zhengjunfeng //CodeString = new byte[colindex+12]; CodeString = new byte[colindex+24];//这里多加了24,表示一个11个字节的手机号和一个字节的分类码 for (rowindex=0;rowindex<11;rowindex++){ temp=textField1.getText().charAt(rowindex); if (temp<='9'&&temp>='0')CodeString[rowindex]=(byte)temp; } CodeString[11]=Kind; for (rowindex=12;rowindex<23;rowindex++){ temp=Sendingmobile.charAt(rowindex-12); if (temp<='9'&&temp>='0')CodeString[rowindex]=(byte)temp; } if (checkbox1.getState()) Kind =0x0A;else Kind =0x05;//0x表示进行发表,0x05表示不进行发表 CodeString[23]=Kind; index = 24; //将整个的编码数组首先初始化 for (rowindex=index;rowindex<colindex;rowindex++) CodeString[rowindex] ='\0'; for (rowindex=0;rowindex<ImageRow;rowindex++){ for (colindex=0;colindex<ImageCol;colindex++){ switch (colindex % 8){ case 0:{if (Data[rowindex][colindex]==1) CodeString[index]|=1;index++;break;} case 1:{if (Data[rowindex][colindex]==1) CodeString[index]|=64;break;} case 2:{if (Data[rowindex][colindex]==1) CodeString[index]|=32;break;} case 3:{if (Data[rowindex][colindex]==1) CodeString[index]|=16;break;} case 4:{if (Data[rowindex][colindex]==1) CodeString[index]|=8;break;} case 5:{if (Data[rowindex][colindex]==1) CodeString[index]|=4;break;} case 6:{if (Data[rowindex][colindex]==1) CodeString[index]|=2;break;} case 7:{if (Data[rowindex][colindex]==1) CodeString[index]|=1;index++;break;} } } if (ImageCol % 8 != 0) index++;//为将来留下接口,如果每一行的想素的个数不是9的整备数据的话,则加上一位 } return; } public void SendMessage() throws IOException{ InetAddress addr = InetAddress.getByName(hostname); Socket socket = new Socket(addr,PORT); try{ BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); //开始进行发送 out.write(CodeString);// int s=in.read(); //ControlButton.setLabel("成功"); WarningDialog WarningDialog1=new WarningDialog(getParentWindow(label1),"错误警告",false); WarningDialog1.setBounds(300, 300, 220, 100); WarningDialog1.setVisible(true); WarningDialog1.label1.setText("图片已经成功的发送到手机上了!"); ControlButton.setLabel("发送"); System.out.println("END"); } finally { socket.close(); } } } //返回给父亲窗口 static Frame getParentWindow(Component compOnApplet){ Container c = compOnApplet.getParent(); while (c != null) { if (c instanceof Frame) return (Frame) c; c = c.getParent(); } return null; } /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Construct the applet*/ public Applet1() { } public void paint(Graphics g){ } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { int row,col; setSize(new Dimension(414, 359)); setLayout(borderLayout1); //this.setBackground(Color.pink); ControlButton.addActionListener(new buttonEvent()); //this.add(ControlButton, BorderLayout.SOUTH); //初始化最初的 Data数组 //ControlPanel.setLayout(xYLayout1); //ControlPanel.add(ControlButton,new XYConstraints(200, 0, 70, 35)); label2.setText("手机号"); textField1.setText("手机号"); choice1.setBackground(Color.lightGray); choice1.addItem("logo"); choice1.addItem("Icon"); choice2.setBackground(Color.lightGray); choice2.addItem("12"); choice2.addItem("10"); choice2.addItem("11"); choice2.addItem("13"); label1.setText("类别"); tf_Str.setEnabled(false); panel.setLayout(gridLayout1); ControlButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { } }); ControlPanel.setLayout(gridLayout2); gridLayout1.setColumns(12); tf_Str.setText("你好"); label3.setText("文字"); gridLayout2.setColumns(6); checkbox1.setLabel("发表"); this.add(ControlPanel, BorderLayout.SOUTH); ControlPanel.add(label3, null); ControlPanel.add(tf_Str, null); ControlPanel.add(choice2, null); ControlPanel.add(label2, null); ControlPanel.add(textField1, null); ControlPanel.add(label1, null); ControlPanel.add(choice1, null); ControlPanel.add(checkbox1, null); ControlPanel.add(ControlButton, null); hostname =getParameter("server"); this.add(mypanel,BorderLayout.CENTER); ImageRow=14; ImageCol=72; for (row=0;row<ImageRow;row++) for (col=0;col<ImageCol;row++) Data[row][col] = 0; } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } //static initializer for setting look & feel static { try { //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -