java代码实现输入框 java 界面输入

java实现计算器的输入框这有什么难的我把我那个代码给你算了是SWing写的import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
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.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;public class TextOne extends JFrame{ /**
* @param args
*/
public String strCo = "";
public double preNum;
public double nextNum;
public int loca;
【java代码实现输入框 java 界面输入】 public boolean flag = false;
public int mark;
public static void main(String[] args) {
// TODO Auto-generated method stub
TextOne frame = new TextOne();
frame.setVisible(true);
}
public TextOne(){
super();
setTitle("计算器");
setBounds(100,100,230,230);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel viewPanel = new JPanel();
getContentPane().add(viewPanel,BorderLayout.NORTH);
final JTextField textField = new JTextField();
textField.setEditable(false);
textField.setHorizontalAlignment(SwingConstants.RIGHT);
textField.setColumns(18);
viewPanel.add(textField);
final JPanel buttonPanel = new JPanel();
final GridLayout gridLayout = new GridLayout(4,4);
gridLayout.setVgap(10);
gridLayout.setHgap(10);
buttonPanel.setLayout(gridLayout);
getContentPane().add(buttonPanel,BorderLayout.CENTER);
String[][] names = {{"1","2","3"," "},
{"4","5","6","-"},
{"7","8","9","*"},
{".","0","=","/"}};
final JButton[][] buttons = new JButton[4][4];
for(int i = 0; i4;i){
for(int j = 0; j4;j){
buttons[i][j] = new JButton(names[i][j]);
buttonPanel.add(buttons[i][j]);
String str = buttons[i][j].getName();
buttons[i][j].addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String str = arg0.getActionCommand();
String cStr = textField.getText();
for(int i = 0; icStr.length();i)
if(cStr.charAt(i) == '='i != cStr.length() - 1){
strCo = null;
flag = false;
preNum = 0;
nextNum = 0;
loca = 0;
break;
}
if(str.equals("0") || str.equals("1")|| str.equals("2")|| str.equals("3")|| str.equals("4")|| str.equals("5")
|| str.equals("6")|| str.equals("7")|| str.equals("8")|| str.equals("9")|| str.equals(".")){
if(flag){
strCo= str;
//textField.setText(textCon);
}
else{
strCo = str;
flag = true;
}
}
else if(str.equals("=")){
String nexN = cStr.substring(loca,cStr.length());
nextNum = toDouble(nexN);
strCo= "=";
double re = 0.0;
switch(mark){
case 0:re = preNumnextNum;break;
case 1:re = preNum - nextNum;break;
case 2:re = preNum * nextNum;break;
case 3:re = preNum / nextNum;break;
}
strCo= re;
}
else{
String preN = cStr;
loca = preN.length()1;
preNum= toDouble(preN);
switch(str.charAt(0)){
case ' ':strCo= " ";mark = 0;break;
case '-':strCo= "-";mark = 1;break;
case '*':strCo= "*";mark = 2;break;
case '/':strCo= "/";mark = 3;break;
}
}
textField.setText(strCo);
}
});
}
}
final JLabel leftLabel = new JLabel();
leftLabel.setPreferredSize(new Dimension(10,0));
getContentPane().add(leftLabel,BorderLayout.WEST);
final JLabel rightLabel = new JLabel();
rightLabel.setPreferredSize(new Dimension(10,0));
getContentPane().add(rightLabel,BorderLayout.EAST);
}
public static double toDouble(String s){
double res = 0.0;
int i = 0;
for(; is.length();i){
if(s.charAt(i) == '.')
break;
else{
res = res * 10s.charAt(i) - '0';
}
}
double dRes = 0.0;
double t = 10;
for(int j = i1; js.length();j){
dRes= (s.charAt(j) - '0') / t;
t *= 10;
}
return resdRes;
}
}
编程实现java程序 。使文本框中可输入文本import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFrame extends JFrame {
JTextArea jta;
JButton jb1, jb2;
public TextFrame() {
jta = new JTextArea();
JScrollPane jsp = new JScrollPane(jta);//带有滚动条java代码实现输入框的组件
add(jsp);
JPanel jp = new JPanel();
jb1 = new JButton("自动换行");
jp.add(jb1);
jb2 = new JButton("不换行");
jp.add(jb2);
add(jp,BorderLayout.SOUTH);
setTitle("文本区示例");
setSize(300, 180);//大小
setLocationRelativeTo(null);//居中
setDefaultCloseOperation(EXIT_ON_CLOSE);//点击窗口关闭按钮,退出
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jta.setLineWrap(true);//自动换行开启
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jta.setLineWrap(false);//自动换行关闭
}
});
}
public static void main(String[] args) {
new TextFrame().setVisible(true);
}
}
java的BS结构如何实现input框扫码输入功能?先来分析一下原理 。
1.js调用手机或者pad终端的摄像头 , 拍照 。
2.苹果或者安卓原生程序获取到拍照的照片路径 , 然后解析图片二维码,将二维码中的内容返回给前台
3.前台将内容显示在input框中 。
网上有现成的来源库,自己搜索一下吧,二维码解析已经很普遍了,没啥难度 。
一般扫描二维码,都是将代码写在硬件里,比如扫码枪,电脑链接扫码枪,直接将扫描内容显示在页面上 。
java怎么添加文本框如果是页面的话:input type="text" name="namevalue" id="namevalue"/;这样就定义了一个input的文本框,注意下,id具有唯一性,不要重复了 。
如果是GUI的话:TextFiled jt=new TextFiled("");这样就定义了一个输入域(文本框),之后通过其他panel(根据实际需要添加)的add(jt)方法进行添加文本框,即可实现 。
怎么用java代码实现将文本框输入的内容按照设计的排版格式import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
public class Ttex {
BufferedImage bi = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB);
public Ttex(String text) {
Graphics gr = bi.createGraphics();
gr.setColor(Color.white);
gr.fillRect(0, 0, bi.getWidth(), bi.getHeight());
gr.setColor(Color.GRAY);
gr.drawString(text, 10, 10);
}
/**
* 根据地址来保存文件
*
* @param dir
*文件地址
*/
private void Save(String dir) {
BufferedImage image = bi;
// 得到系统支持的图片写入器
Iterator it = ImageIO.getImageWritersBySuffix("jpg");
ImageWriter iw = null;
if (it.hasNext()) {
try {
ImageOutputStream imgOut = ImageIO
.createImageOutputStream(new File(dir));
iw = (ImageWriter) it.next();
iw.setOutput(imgOut);
IIOImage iioi = new IIOImage(image, null, null);
iw.write(iioi);
imgOut.close();
iw.dispose();
} catch (IOException e1) {
}
}
}
public static void main(String[] args) {
Ttex m = new Ttex("0123456789");
m.Save("D:/1.jpg");
}
}
JAVA 文本框输入import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestSwing implements ActionListener
{
private JTextField tf;
private JFrame f;
private JLabel lb;
private JButton btok;
public TestSwing()
{
f=new JFrame("测试");
Container c=f.getContentPane();
c.setLayout(new FlowLayout());
lb=new JLabel("用户名:");
c.add(lb);
tf=new JTextField(16);
c.add(tf);
btok=new JButton("ok");
c.add(btok);
btok.addActionListener(this);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setSize(300,400);
f.setVisible(true);
f.setResizable(true);
}
public void actionPerformed(ActionEvent e)
{
String s="";
if(e.getSource()==btok)
{
s=tf.getText();
if(s.length()5||s.length()20)
{
JOptionPane.showMessageDialog(null,"你输入的字符不符合要求","警告",1);
tf.setText("");
}
else
{
System.out.println("你输入的正确");
}
}
}
public static void main(String[] args)
{
new TestSwing();
}
}
我写了一个是可以通过的,你试一下吧 。
good luck to you!
关于java代码实现输入框和java 界面输入的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读