html的代码如何实现的输入文字,要求黑色字体,14号字体大小,居中
时间: 2024-03-24 17:37:29 浏览: 6
你可以使用以下HTML代码实现输入文字,要求黑色字体,14号字体大小,居中:
```html
<div style="text-align:center; font-size: 14px; color: black;">输入文字</div>
```
其中,`text-align:center` 属性用于实现文字居中,`font-size: 14px` 属性用于设置字体大小为14号,`color: black` 属性用于设置字体颜色为黑色。你可以将“输入文字”替换成你想要的内容。
相关问题
java编写一个登录界面,含有文本框、密码框和登录按钮,要求界面背景和控件背景颜色为黄色,文字颜色为红色,字体为14号楷体
以下是一个简单的 Java 登录界面示例代码,其中包括文本框、密码框和登录按钮,界面背景和控件背景颜色均为黄色,文字颜色为红色,字体为14号楷体:
```
import javax.swing.*;
import java.awt.*;
public class LoginFrame extends JFrame {
public LoginFrame() {
// 设置窗口标题
setTitle("登录界面");
// 设置窗口大小
setSize(400, 300);
// 设置窗口居中
setLocationRelativeTo(null);
// 设置窗口关闭时退出程序
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 创建面板
JPanel panel = new JPanel();
// 设置面板布局
panel.setLayout(new GridLayout(3, 2, 10, 10));
// 创建用户名标签和文本框
JLabel usernameLabel = new JLabel("用户名:");
usernameLabel.setForeground(Color.RED);
usernameLabel.setFont(new Font("楷体", Font.PLAIN, 14));
JTextField usernameField = new JTextField();
usernameField.setBackground(Color.YELLOW);
// 创建密码标签和密码框
JLabel passwordLabel = new JLabel("密 码:");
passwordLabel.setForeground(Color.RED);
passwordLabel.setFont(new Font("楷体", Font.PLAIN, 14));
JPasswordField passwordField = new JPasswordField();
passwordField.setBackground(Color.YELLOW);
// 创建登录按钮
JButton loginButton = new JButton("登录");
loginButton.setForeground(Color.RED);
loginButton.setFont(new Font("楷体", Font.PLAIN, 14));
// 将标签、文本框和按钮添加到面板中
panel.add(usernameLabel);
panel.add(usernameField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(new JLabel());
panel.add(loginButton);
// 将面板添加到窗口中
add(panel);
// 显示窗口
setVisible(true);
}
public static void main(String[] args) {
new LoginFrame();
}
}
```
在这个示例代码中,我们创建了一个继承自 JFrame 的类 LoginFrame,该类包含了一个带有文本框、密码框和登录按钮的登录界面。我们使用 JPanel 来创建一个面板,并将标签、文本框和按钮添加到面板中。我们还使用 setForeground、setFont 和 setBackground 方法来设置文本颜色、字体和背景颜色。最后,我们将面板添加到窗口中并显示窗口。
以下程序通过FlowLayout布局管理器实现对组件的操作。请按照提示,完善程序。 程序运行结果如下图所示: import javax.swing.*; import java.awt.*; public class Main extends JFrame { public Main() { setLayout(________);//设置窗体为流式布局,无参数默认为居中对齐 setFont(new Font("Helvetica",________, 14));//设置窗体中显示的字体样式,加粗,14号 getContentPane().add(new JButton("Button 1"));//将按钮添加到窗体中 getContentPane().add(new JButton("Button 2")); getContentPane().add(new JButton("Button3")); getContentPane().add(new JButton("Button 4")); } public static void main(String args[]) { Main window = new Main(); window.setTitle("________");//设置窗体标题 window.pack();//该代码依据放置的组件设定窗口的大小使之正好能容纳你放置的所有组件 window.setVisible(true); window.setDefaultCloseOperation(________);//设置窗体的默认关闭方式 window.setLocationRelativeTo(null); //让窗体居中显示 } }
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
setLayout(new FlowLayout());//设置窗体为流式布局,无参数默认为居中对齐
setFont(new Font("Helvetica", Font.BOLD, 14));//设置窗体中显示的字体样式,加粗,14号
getContentPane().add(new JButton("Button 1"));//将按钮添加到窗体中
getContentPane().add(new JButton("Button 2"));
getContentPane().add(new JButton("Button3"));
getContentPane().add(new JButton("Button 4"));
}
public static void main(String args[]) {
Main window = new Main();
window.setTitle("FlowLayout Demo");//设置窗体标题
window.pack();//该代码依据放置的组件设定窗口的大小使之正好能容纳你放置的所有组件
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗体的默认关闭方式
window.setLocationRelativeTo(null); //让窗体居中显示
}
}