重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
import javax.swing.*;
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比灌南网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式灌南网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖灌南地区。费用合理售后完善,十年实体公司更值得信赖。
import java.awt.*;
public class test extends JFrame{
public test(){
JButton button; //按钮
JLabel label; //标签
JComboBox combobox;//下拉菜单
JCheckBox checkbox;//复选框
JRadioButton radiobutton;//单选框
JTextField textfield;//文本框
button = new JButton("按钮");
label = new JLabel("标签:");
checkbox = new JCheckBox("复选框一");
radiobutton = new JRadioButton("单选框一");
combobox = new JComboBox();
textfield = new JTextField(100);
Container c = this.getContentPane();
c.setLayout(new FlowLayout());
c.add(button);
c.add(label);
c.add(checkbox);
c.add(radiobutton);
combobox.addItem("1");
combobox.addItem("2");
c.add(combobox);
c.add(textfield);
setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
// TODO 自动生成方法存根
test mytest = new test();
}
}
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");
}
}
写了一个很简单的案例,可以参考和修改
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class FromeDemo extends JFrame{
JButton jbutton;
public FromeDemo() {
jbutton = new JButton("弹出2个文本框");
jbutton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JDialog jd = new JDialog();
jd.setBounds(320, 180, 260, 100);
jd.setTitle("弹出文本框");
jd.getContentPane().setLayout(new GridLayout(2, 2));
jd.add(new JLabel("文本框一"));
jd.add(new JTextField(80));
jd.add(new JLabel("文本框二"));
jd.add(new JTextField(80));
jd.setModal(true);//确保弹出的窗口在其他窗口前面
jd.setVisible(true);
}
});
add(jbutton,BorderLayout.SOUTH);
setBounds(300, 100, 320, 320);
setTitle("测试");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]) {
new FromeDemo();
}
}
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);//带有滚动条的组件
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);
}
}