
java初学者遇到小问题求大神帮帮忙十分感谢 10
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.awt.Dimension;...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Dimension;
class HelloWorld extends JPanel
{
static final int WIDTH=300;
static final int HEIGHT=150;
JFrame loginframe;
public void add(Component c,GridBagConstraints constraints,int x ,int y,int w,int h)
{
constraints.gridx=x;
constraints.gridy=y;
constraints.gridwidth=w;
constraints.gridheight=h;
add(c,constraints);
}
HelloWorld()
{
loginframe=new JFrame("欢迎进入Java世界");
loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout lay=new GridBagLayout();
GridBagLayout setLayout = (lay);
loginframe.add(this,BorderLayout.WEST);
loginframe.setSize(WIDTH,HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=Screen.Size.width;
int height=Screen.Size.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
loginframe.setLocation(x,y);
JButton ok=new JButton("登录");
JButton cacel=new JButton("放弃");
JLabel title=new JLabel("欢迎进入Java世界");
JLabel name=new JLabel("用户名");
JLabel password=new JLabel("密码");
final JTextField nameinput=new JTextField(15);
final JTextField passwordinput=new JTextField(15);
GridBagConstraints constraints=new GridBagConstraints();
constraints.fill=GridBagConstraints.NONE;
constraints.anchor=GridBagConstraints.EAST;
constraints.weightx=3;
constraints.weighty=4;
add(title,constraints,0,0,4,1);
add(name,constraints,0,0,0,1);
add(password,constraints,0,2,1,1);
add(nameinput,constraints,2,1,1,1);
add(passwordinput,constraints,2,2,1,1);
add(ok,constraints,0,3,1,1);
add(cacel,constraints,2,3,1,1);
loginframe.setResizable(false);
loginframe.setVisible(true);
}
public static void main(String[] args)
{HelloWorld hello=new HelloWorld();
}
}
int width=Screen.Size.width;
int height=Screen.Size.height;
int width=Screen.Size.width;
int height=Screen.Size.height;老说什么screen cant be resovled 展开
import java.awt.*;
import java.awt.event.*;
import java.awt.Dimension;
class HelloWorld extends JPanel
{
static final int WIDTH=300;
static final int HEIGHT=150;
JFrame loginframe;
public void add(Component c,GridBagConstraints constraints,int x ,int y,int w,int h)
{
constraints.gridx=x;
constraints.gridy=y;
constraints.gridwidth=w;
constraints.gridheight=h;
add(c,constraints);
}
HelloWorld()
{
loginframe=new JFrame("欢迎进入Java世界");
loginframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout lay=new GridBagLayout();
GridBagLayout setLayout = (lay);
loginframe.add(this,BorderLayout.WEST);
loginframe.setSize(WIDTH,HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=Screen.Size.width;
int height=Screen.Size.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
loginframe.setLocation(x,y);
JButton ok=new JButton("登录");
JButton cacel=new JButton("放弃");
JLabel title=new JLabel("欢迎进入Java世界");
JLabel name=new JLabel("用户名");
JLabel password=new JLabel("密码");
final JTextField nameinput=new JTextField(15);
final JTextField passwordinput=new JTextField(15);
GridBagConstraints constraints=new GridBagConstraints();
constraints.fill=GridBagConstraints.NONE;
constraints.anchor=GridBagConstraints.EAST;
constraints.weightx=3;
constraints.weighty=4;
add(title,constraints,0,0,4,1);
add(name,constraints,0,0,0,1);
add(password,constraints,0,2,1,1);
add(nameinput,constraints,2,1,1,1);
add(passwordinput,constraints,2,2,1,1);
add(ok,constraints,0,3,1,1);
add(cacel,constraints,2,3,1,1);
loginframe.setResizable(false);
loginframe.setVisible(true);
}
public static void main(String[] args)
{HelloWorld hello=new HelloWorld();
}
}
int width=Screen.Size.width;
int height=Screen.Size.height;
int width=Screen.Size.width;
int height=Screen.Size.height;老说什么screen cant be resovled 展开
展开全部
你自己找到问题了哦,
int width=Screen.Size.width;
int height=Screen.Size.height;
这两行代码,Screen.Size.width是什么东西呢?你自己写的代码应该知道吧?
我改为
int width = screenSize.width;
int height = screenSize.height;
运行正常。
int width=Screen.Size.width;
int height=Screen.Size.height;
这两行代码,Screen.Size.width是什么东西呢?你自己写的代码应该知道吧?
我改为
int width = screenSize.width;
int height = screenSize.height;
运行正常。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把
int width=Screen.Size.width;
int height=Screen.Size.height;
里的Screen.Size 换成 screenSize 这是你自己创建的对象,能够获得屏幕的宽和高
int width=Screen.Size.width;
int height=Screen.Size.height;
里的Screen.Size 换成 screenSize 这是你自己创建的对象,能够获得屏幕的宽和高
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
因为没找到Screen这个对象,看你程序好像应该如下
int width = screenSize.width;
int height = screenSize.height;
int width = screenSize.width;
int height = screenSize.height;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询