自己簡單寫了一下代碼,可以學(xué)習(xí)下:
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計制作、成都網(wǎng)站制作、坪山網(wǎng)絡(luò)推廣、微信小程序開發(fā)、坪山網(wǎng)絡(luò)營銷、坪山企業(yè)策劃、坪山品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供坪山建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:www.rwnh.cn
界面代碼:
inputDateText=new?JTextField();
inputDateText.setText("yyyy-MM-dd");
JPanel?inputDatePanel=new?JPanel();
inputDatePanel.setLayout(new?GridLayout(3,?1));//?網(wǎng)格布局,分成兩行一列
inputDatePanel.add(inputDateLabel);
inputDatePanel.add(inputDateText);
//?添加確認(rèn)按鈕
JPanel?btnPanel=new?JPanel();
confirmBtn=new?JButton("確認(rèn)");
confirmBtn.addActionListener(this);
btnPanel.add(confirmBtn);?//?JPanel默認(rèn)就是FlowLaout居中對齊
inputDatePanel.add(btnPanel);
JPanel?emptyPanel=new?JPanel();
emptyPanel.setSize(150,?240);
p3.add(emptyPanel);?//右側(cè)中間部分填充
p3.add(inputDatePanel,BorderLayout.SOUTH);
2、按鈕事件
if?(e.getSource()?==?confirmBtn)?{?//?點擊輸入日期文本框下方的確認(rèn)按鈕
String?dateText?=?inputDateText.getText();
if?(dateText==null?||?"".equals(dateText.trim()))?{
JOptionPane.showMessageDialog(null,?"請輸入日期!");
inputDateText.setText("yyyy-MM-dd");
return;
}?else?{
dateText=dateText.trim();
if?(dateText.trim().length()==10?||?dateText.matches(DATEREGEX))?{
//?
}?else?{
JOptionPane.showMessageDialog(null,?"輸入的日期不符合格式,請重新輸入!");
inputDateText.setText("yyyy-MM-dd");
return;
}
SimpleDateFormat?dateFormat=new?SimpleDateFormat("yyyy-MM-dd");
Date?inputDate=null;
try?{
inputDate=dateFormat.parse(dateText);
}?catch?(ParseException?e1)?{?//?用戶輸入的日期不符合格式
e1.printStackTrace();
inputDateText.setText("yyyy-MM-dd");
JOptionPane.showMessageDialog(null,?"輸入的日期不符合格式,請重新輸入!");
return;
}
Calendar?calendar=Calendar.getInstance();
calendar.setTime(inputDate);
jtfYear.setText(calendar.get(Calendar.YEAR)+"");?//?根據(jù)輸入的日期解析出年月填寫到年月文本框
jtfMonth.setText(calendar.get(Calendar.MONTH)+1+"");
calendar.setTime(new?Date());
}
}
你的代碼里沒繪制背景的代碼?,而且,你也沒有調(diào)用父類的方法,去繪制
我?guī)湍愀母?/p>
public void paint(Graphics g) {
setBackground(Color.cyan);
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
int red, green, blue;
red = 255;
blue = 255;
green = 0;
g2.setPaint(new Color(red, green, blue));
g2.drawString("Welcome to Xi\047an", 25, 75);
showStatus("Current RGB:" + g2.getPaint().toString());
}
在使用EditText的XML 文件中加入一個屬性:
android:textCursorDrawable="@null"
android:textCursorDrawable 這個屬性是用來控制光標(biāo)顏色的,
"@null" 是作用是讓光標(biāo)顏色和text color一樣
f.add(lab);
這么加的話,根據(jù)JFrame的默認(rèn)框架lab會被放在f的中間并鋪滿整個f,所以你看到的白色是lab的背景,不是f的背景。
網(wǎng)頁名稱:Java中白色代碼 java藍(lán)色代碼
分享URL:http://www.rwnh.cn/article8/dosphop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、網(wǎng)站導(dǎo)航、、全網(wǎng)營銷推廣、App開發(fā)、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)