Swing是一个用于开发Java应用程序用户界面的开发工具包。
以抽象窗口工具包(AWT)为基础使跨平台应用程序可以使用任何可插拔的外观风格。Swing开发人员只用很少的代码就可以利用Swing丰富、灵活的功能和模块化组件来创建优雅的用户界面。
工具包中所有的包都是以swing作为名称,例如javaxswing,javaxswingevent。
我真的是抽风了,手痒了,给你写了这段代码,如果楼主、、、
嘻嘻,追点分给我吧
import javaawt;
import javaawtevent;
import javaio;
import javaxswing;
public class baidu_9 extends JFrame implements ActionListener
{
static final String OUTPUT="C://Testtxt";
JPanel pnl;
JLabel lbl;
JTextField txt1,txt2;
JButton btnCopy,btnClear,btnOutput,btnColor;
public baidu_9()
{
super("百度题目");
pnl=new JPanel();
thissetContentPane(pnl);
pnlsetLayout(null);
pnlsetBackground(ColorWHITE);
lbl=new JLabel("百度");
txt1=new JTextField(10);
txt2=new JTextField(10);
btnCopy=new JButton("复制");
btnCopyaddActionListener(this);
btnClear=new JButton("清除");
btnClearaddActionListener(this);
btnOutput=new JButton("写入");
btnOutputaddActionListener(this);
btnColor=new JButton("变色");
btnColoraddActionListener(this);
lblsetBounds(100, 10, 80, 20);
txt1setBounds(10, 40, 100, 20);
txt2setBounds(120, 40, 100, 20);
btnCopysetBounds(10, 70, 60, 20);
btnClearsetBounds(75, 70, 60, 20);
btnOutputsetBounds(140, 70, 60, 20);
btnColorsetBounds(205, 70, 60, 20);
pnladd(lbl);
pnladd(txt1);
pnladd(txt2);
pnladd(btnCopy);
pnladd(btnClear);
pnladd(btnOutput);
pnladd(btnColor);
setSize(300,150);
setVisible(true);
}
public void Copy()
{
txt2setText(txt1getText());
}
public void Clear()
{
txt1setText("");
txt2setText("");
pnlsetBackground(ColorWHITE);
}
public void Color()
{
pnlsetBackground(ColorBLACK);
}
public void Ouput()
{
try
{
File fl=new File("C:\\Testtxt");
FileWriter fw = new FileWriter(fl);
BufferedWriter bw = new BufferedWriter(fw);
bwwrite(txt1getText());
bwclose();
}
catch (IOException e)
{
eprintStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{
if(egetSource()==btnCopy)
thisCopy();
if(egetSource()==btnClear)
thisClear();
if(egetSource()==btnColor)
thisColor();
if(egetSource()==btnOutput)
thisOuput();
}
public static void main(String[] args)
{
new baidu_9();
}
}
Swing和AWT 这两个是java的包。用它们可以实现界面窗口。如果不知道做法,可以百度一下。java的API帮助文档一定要有,当遇到用Swing和AWT的一些用法不知道时可以查询帮助文档。java窗口和mysql的链接基本和做网站差不多,具体看你是准备做成本机应用程序,还是B/S结构。
c++有自己的编程界面是因为我们先装的是编译器,比如Devc++,VC++之类的,我们可以利用这些编译器编写程序然后进行调试
而对于java来讲,我们装的是运行环境,对于很多人,并不需要自己写代码,而只需要这个运行环境来运行java语言写好了的应用程序。
要是想要有编程界面的话可以另外下java的编译器比如eclipse等
import javaawt;
import javaawtevent;
import javautil;
import javaxswing;
import javaxswingborderBorder;
class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private Map<String, Integer> sizes = new HashMap<String, Integer>();
private Map<String, Integer> styles = new HashMap<String, Integer>();
private Map<String, Integer> toppings = new HashMap<String, Integer>();
public MainFrame() {
sizesput("Extra Large", 10);
sizesput("Large", 8);
sizesput("Medium", 5);
sizesput("Small", 3);
stylesput("Deep Dish", 20);
stylesput("Regular", 10);
stylesput("Thin Crust", 5);
stylesput("Chicago", 3);
toppingsput("Cheese", 8);
toppingsput("Tomato", 7);
toppingsput("Peppers", 6);
toppingsput("Peperoni", 5);
thissetTitle("布局及事件处理");
thissetSize(450, 350);
thissetLayout(new BorderLayout());
thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
JLabel lblTitle = new JLabel();
lblTitlesetText("Pizzeria Juno");
lblTitlesetFont(new Font("宋体", FontBOLD, 36));
lblTitlesetHorizontalAlignment(SwingConstantsCENTER);
thisadd("North", lblTitle);
JPanel bodyPanel = new JPanel();
bodyPanelsetLayout(new GridLayout(2, 1));
thisadd("Center", bodyPanel);
JPanel listPanel = new JPanel();
listPanelsetLayout(new GridLayout(1, 3));
listPanelsetSize(200, 200);
bodyPaneladd(listPanel);
Border lineBorder = BorderFactorycreateLineBorder(ColorBLACK);
JPanel sizePanel = new JPanel();
sizePanelsetLayout(new BorderLayout());
listPaneladd(sizePanel);
JLabel sizeTitle = new JLabel();
sizeTitlesetText("Sizes");
sizePaneladd("North", sizeTitle);
JList sizeList = new JList(sizeskeySet()toArray());
sizeListsetSize(100, 100);
sizeListsetBorder(lineBorder);
sizeListsetSelectionMode(ListSelectionModelSINGLE_SELECTION);
sizePaneladd(sizeList);
JPanel stylePanel = new JPanel();
stylePanelsetLayout(new BorderLayout());
listPaneladd(stylePanel);
JLabel styleTitle = new JLabel();
styleTitlesetText("Styles");
stylePaneladd("North", styleTitle);
JList styleList = new JList(styleskeySet()toArray());
styleListsetSize(100, 100);
styleListsetBorder(lineBorder);
styleListsetSelectionMode(ListSelectionModelSINGLE_SELECTION);
stylePaneladd(styleList);
JPanel toppingPanel = new JPanel();
toppingPanelsetLayout(new BorderLayout());
listPaneladd(toppingPanel);
JLabel toppingTitle = new JLabel();
toppingTitlesetText("Toppings");
toppingPaneladd("North", toppingTitle);
JList toppingList = new JList(toppingskeySet()toArray());
toppingListsetSize(100, 100);
toppingListsetBorder(lineBorder);
toppingPaneladd(toppingList);
JTextArea txtResult = new JTextArea();
txtResultsetEditable(false);
bodyPaneladd(txtResult);
JPanel bottomPanel = new JPanel();
bottomPanelsetLayout(new GridLayout(1, 3));
thisadd("South", bottomPanel);
JLabel label1 = new JLabel("Click to complete order");
bottomPaneladd(label1);
JButton btnRingUp = new JButton("Ring up");
btnRingUpaddActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(sizeListgetSelectedValue() == null) {
JOptionPaneshowMessageDialog(MainFramethis, "Please select size");
return;
}
if(styleListgetSelectedValue() == null) {
JOptionPaneshowMessageDialog(MainFramethis, "Please select style");
return;
}
if(toppingListgetSelectedValue() == null) {
JOptionPaneshowMessageDialog(MainFramethis, "Please select topping");
return;
}
float total = 0;
String size = sizeListgetSelectedValue()toString();
total += sizesget(size);
String style = styleListgetSelectedValue()toString();
total += stylesget(style);
String result = size + " Pizza, " + style + " Style";
Object[] toppings = toppingListgetSelectedValues();
for(Object topping : toppings) {
result += "\n +" + toppingtoString();
total += MainFramethistoppingsget(toppingtoString());
}
result += "\n Total: " + total;
txtResultsetText(result);
}
});
bottomPaneladd(btnRingUp);
JButton btnQuit = new JButton("Quit");
btnQuitaddActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MainFramethisdispose();
}
});
bottomPaneladd(btnQuit);
}
}
public class App {
public static void main(String[] args) {
MainFrame mainFrame = new MainFrame();
mainFramesetVisible(true);
}
}
以上就是关于JAVA 用什么做界面程序全部的内容,包括:JAVA 用什么做界面程序、JAVA图形界面程序编写、java能不能直接做界面窗口等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)